【发布时间】:2014-12-09 08:39:16
【问题描述】:
我有在弹出模式中呈现创建视图的渲染操作。但是模型不允许传递类别的id,并调用错误:
The parameters dictionary contains a null entry for parameter 'categoryId' of non-nullable type
'System.Int32' for method 'System.Web.Mvc.ActionResult Create(Int32)' in
'PasswordCloudApp.Controllers.EntryController'. An optional parameter must be a reference type,
a nullable type, or be declared as an optional parameter.
索引视图:
@model PagedList.IPagedList<PasswordCloudApp.ViewModels.EntryViewModel>
@{Html.RenderAction("Create", "Entry", new { categoryId = Model.CategoryId -->
but don't allow to access .CategoryId });}
@Html.Partial("_Entries", Model)
动作方法索引:
public ActionResult Index(int categoryId, int page = 1)
{
var category = _db.Categories.Find(categoryId);
var model =
db.Query<Entry>()
.OrderBy(en=>en.Id)
.Where(en=>en.CategoryId == categoryId)
.Select(en => new EntryViewModel
{
Id = en.Id,
Title = en.Title,
Username = en.Username,
Password = en.Password,
Url = en.Url,
Description = en.Description,
}).ToPagedList(page, 10);
return View(model);
}
关于如何将 CategoryId 传递给 RenderAction 有什么建议吗?
【问题讨论】:
标签: asp.net asp.net-mvc entity-framework asp.net-mvc-4