How to set the static text into JsonResult?

允我心安 提交于 2019-12-06 04:30:43

Is this what you are looking for

return new JsonResult { Text = "Abc", Value="123" };

If you want to add a new element to the drop down at start then

var editedProducts = new SelectList(products.ToList(), "ProductID","ProductName" ).ToList();
editedProducts.insert(0, new SelectListItem() { Value = "123", Text = "Abc" });

return new JsonResult { Data = editedProducts };
public ActionResult _AjaxLoading(string text
{
  var data = new { Text= "123", Value= "Abc"};
  return Json(data, JsonRequestBehavior.AllowGet);
}

If it is an HTTPGet method, You should specify JsonRequestBehavior.AllowGet as second parameter to return JSon data from a GET method

It looks like you are in need of this:

return new JsonResult { Data = new { Text="Abc", Value="123", Produtcs= new SelectList(products.ToList(), "ProductID", "ProductName") }};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!