Last active
August 29, 2015 14:09
-
-
Save tobbbe/1cb1497deb9155b83db3 to your computer and use it in GitHub Desktop.
JSON in razor view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using Newtonsoft.Json | |
Response.Clear(); | |
Response.Buffer = true; | |
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; | |
Response.Write(JsonConvert.SerializeObject(new { | |
Fraktkostnad = @shop.Basket.FormattedShippingAmount, | |
Total = @shop.Basket.FormattedRowTotalAmount, | |
Moms = @shop.Basket.FormattedRowTotalVatAmount | |
})); | |
Response.End(); | |
_________________________________________________ | |
var machines = Model.Content.Children.Where(x => x.Name.ToLower().Contains(searchstring)); | |
var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); | |
string jsonmachines = javaScriptSerializer.Serialize( | |
machines.Select(x => new | |
{ | |
x.Name, | |
x.Url | |
})); | |
<script type="text/javascript"> | |
var begmachines = @Html.Raw(jsonmachines); | |
if (begmachines) { | |
initMachineSort(); | |
} | |
function initMachineSort() { | |
var asd = "asd"; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment