著者のリストを表示するために私のビューにドロップダウンリストを使用しようとしています。私はこのドロップダウンに値を設定して、私の見解でコンテンツを見ることができます。私のフォームを送信するとき、私は私のコントローラで私のアクションをデバッグし、私のモデルを調べるとき、私のドロップダウンに関連するフィールドの値はnullです。ここフォームが送信されたときにドロップダウンリストの値がありません
が(私のビューを表示する前に)私のアクションコントローラである:ここ
public ActionResult Create()
{
IEnumerable<User> authors = m_AccountBusiness.GetAllUsers();
PageCreateViewModel viewModel = new PageCreateViewModel
{
PageToCreate = new PageFullViewModel(),
Authors = authors.Select(x => new SelectListItem { Text = x.UserName, Value = x.UserID.ToString() })
};
return View(viewModel);
}
は私のビュー(の一部)である:ここ
@model MyBlog.ViewModels.PageCreateViewModel
<h3>Create</h3>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.PageToCreate.PageID)
<div class="editor-label">
@Html.LabelFor(model => model.PageToCreate.Title)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.PageToCreate.Title, new { @class = "titleValue" })
@Html.ValidationMessageFor(model => model.PageToCreate.Title)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.PageToCreate.Author)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.PageToCreate.Author, Model.Authors, "Please select...")
</div>
は私PageCreateViewModelある:
public class PageCreateViewModel
{
public PageFullViewModel PageToCreate { get; set; }
public IEnumerable<SelectListItem> Authors { get; set; }
}
ご存じですか?
ありがとうございました。
ご回答ありがとうございますが動作しません。私はまだ私のコントローラにドロップダウンの値が戻っていません。 – Bronzato
@Bronzatoそして、あなたのモデルの他の値は返品時に正しく記入されますか? – JoJa