我的控制器:ASP MVC EF多選HTTP POST
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(BlogCompModel blogmodel)
{
if (ModelState.IsValid)
{
...
}
}
筆者認爲:在後
@model BlogProject.Models.BlogCompModel
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
...
<div class="form-group">
@Html.LabelFor(model => model.BlogCompModel.posts, "Property", new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.ListBoxFor(model => model.posts, new MultiSelectList(Model.posts, "post_ID", "postTitle"))
@Html.ValidationMessageFor(model => model.posts.posts)
</div>
</div>
}
錯誤消息:
"The parameter conversion from type 'System.String' to type 'BlogProject.Models.Posts' failed because no type converter can convert between these types."} System.Exception {System.InvalidOperationException}
正如您所看到的,我不確定如何將HTML Multiselect列表從Post_ID集合轉換爲文章的ICollection。
謝謝!
我不處理多用MVC,但這裏是一個鏈接,可以幫助你(HTTP://論壇。 asp.net/t/1778536.aspx) – James