【发布时间】:2011-02-04 19:25:37
【问题描述】:
相关帖子:Populating a select box in a form using related ID in MVC3
我有一个使用 MVC3 和 ADO.NET Linq-to-Entities 生成的 Listview。
我已经能够创建一个简单的列表视图,使用“创建”和“编辑”操作链接命令来创建“相关对象”。
@Html.ActionLink("Create Shipping Profile", "../PrintProfile/Create", new { id = item.ProductId }) |
@Html.ActionLink("Edit Shipping Profile", "../PrintProfile/Edit", new { id = item.ProductId })
当我创建 'PrintProfile' 我希望“创建”视图使用“ProductId”(这是数据库表关系)“预填充”,以便我可以创建配置文件,然后编辑列表中每个项目的关联配置文件。
这是 PrintProfile 的创建控制器:
public ActionResult Create(int ProductId)
{
var entities = new CS_ShippingProfiles();
entities.ProductId = ProductId; // Assign the ProductId I want to 'create'
return View(entities);
}
[HttpPost]
public ActionResult Create(CS_ShippingProfiles Profile)
{
if (ModelState.IsValid)
{
var entities = new LabelServiceEntities();
entities.AddToCS_ShippingProfiles(Profile);
entities.SaveChanges();
return Redirect("/Products");
}
return View(Profile);
}
但是当我点击链接时,我得到一个“空”参数异常!我做错了什么?!
【问题讨论】:
标签: linq-to-entities asp.net-mvc-3 ado.net-entity-data-model