-1
这是我的含有1至许多关系动态添加/在ASP.NET MVC除去项阵列属性4次
public class RealEstate
{
public int ValueUSD { get; set; }
public string Address { get; set; }
}
public class RealEstateAgent
{
public string FirstName { get; set; }
public string LastName { get; set; }
public RealEstate[] HandledRealEstates { get; set; }
}
这里简化模型是我的控制器类:
public class AgentController : Controller
{
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(RealEstateAgent agent)
{
try
{
int realestateCount = agent.HandledRealEstates.Length;
Console.WriteLine("Agent {0} handles {1} real estates.", agent.FirstName, realestateCount);
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
业务需求是允许用户通过使用房地产的添加/删除按钮在单个页面上创建/编辑代理与他们的房地产一起。
我是ASP.NET MVC中的新手,刚刚学习这些概念。 任何人都可以向我展示一个例子,我的创建视图应该是什么样子,以便让模型绑定MVC-ish方式?
你应该阅读这篇文章http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/。 – xurca