I'm completely new in .NET core world. I faced a problem with converting @foreach (var item in Model.Products) into JavaScript array holding JSON product object (id, name). I tried solutions found in Stack Overflow and in some blogs, but each of them ends up in from server status 500 to ignored assignment.
Wrong attempts:
var yourjavascriptArray = <%=new JavaScriptSerializer().Serialize(cSharpArrayName);%>;
var inData = @Html.Raw(Json.Encode(Model.Products));
Code that is used:
Controller:
public IActionResult Index(string searchkey)
{
...
return View(new Models.ProductSearcherModel() { SearchKey = searchkey, Products = prods
});
Index.cshtml:
@foreach (var item in Model.Products)
{
//how to assign Model.Products to js array?
}
