Skip to content

Instantly share code, notes, and snippets.

@tobbbe
Last active August 29, 2015 14:09
Show Gist options
  • Save tobbbe/1cb1497deb9155b83db3 to your computer and use it in GitHub Desktop.
Save tobbbe/1cb1497deb9155b83db3 to your computer and use it in GitHub Desktop.
JSON in razor view
@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