如何将Ienumerable模型传递给Controller [英] How to pass Ienumerable model to Controller
本文介绍了如何将Ienumerable模型传递给Controller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HI,
如何将Ienumerable modelView传递给控制器Actionresult ..我尝试了以下代码
how to pass Ienumerable modelView to controller Actionresult.. I tried the following code
<br />
<pre lang="xml"><br />
[HttpPost] <br />
public ActionResult PostingComment(IEnumerable<NotificationModel> vii)<br />
{<br />
<br />
return View(vii);<br />
}</pre><br />
<br />
br mode="hold" />but the code is not hitting when using in
Thanks
BS
推荐答案
你可以使用ToList()方法将Ienumerable传递给模型。
you can use ToList() method to pass Ienumerable to a model.
return View(vii.ToList());
简单来说
1.假设你有一个班级
In simple terms
1. Say suppose you have a class
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
}
2.您的控制器可能是
2. You controller could be
public ActionResult Contact(Student student)
{
ViewBag.Message = "Your contact page.";
ViewBag.id = student.Id;
ViewBag.name = student.Name;
return View(student);
}
3.您的观点可能是
3. Your view could be
@model Mvc.Models.Student
YOUR ID = @Model.Id
YOUR NAME = @Model.Name
[HttpPost]
public ActionResult PostingComment(IEnumerable<NotificationModel> vii)
{
return View(vii.AsEnumerable());
}
这篇关于如何将Ienumerable模型传递给Controller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文