[英]How to pass JsonResult to view in asp.net mvc
I have a business model class that have put some value then business model class to pass in model class properties.Now I want to pass the value in view page.我有一个业务 model class 已经投入了一些价值然后业务 model class 传递 model class 属性。现在我想传递视图页面中的值。 But I can't use Viewbag because its required a collection.That why I can't pass value in view page.
但我不能使用 Viewbag,因为它需要一个集合。这就是为什么我不能在视图页面中传递值的原因。
Is it possible to pass value in view page??是否可以在视图页面中传递值?
If possible.如果可能的话。 how to pass it?
如何通过呢?
public async Task<JsonResult> GetDeptName(int studentId)
{
var model = _scope.Resolve<FormModel>();
if (ModelState.IsValid)
{
await model.DeptList(studentId);
}
return Json(new {model.DeptId, model.DeptName });
}
You can pass concrete objects just like this to the View() as a parameter:您可以像这样将具体对象作为参数传递给 View():
public ActionResult YourMethod()
{
model = new YourModelObject
{
// Fill your properties here
};
return View(model);
}
In the page.cshtml you can set the model like this:在 page.cshtml 中,您可以像这样设置 model:
@model YourModelObject
And use like this:并像这样使用:
@Html.LabelFor(x => x.YourProperty)
@Html.EditorFor(x => x.YourPropery)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.