物品ビューモデルはasp.netのMVC 3
public class ArticleViewModel : ViewModelBase
{
[Required(ErrorMessage = "Required")]
public string Title { get; set; }
[Required(ErrorMessage = "Choose the language")]
public BELocale Locale { get; set; }
}
public class BELocale : BEEntityBase
{
public string OriginalName { get; set; }
public string FriendlyName { get; set; }
public string TwoLetterISOName { get; set; }
}
ビュー "AddLocaleForArticle"
@model Models.ArticleViewModel
@using (Html.BeginForm("VefifyAddingLocaleForArticle", "Administration"))
{
@Html.TextBoxFor(m => m.Title, new { disabled = "disabled" })
@Html.DropDownListFor(m => m.Locale,
new SelectList(ViewBag.AvalaibleLocales, "ID", "OriginalName"), "Select a language"
)
@Html.ValidationMessageFor(m => m.Locale)
<input type="submit" value="Save" />
}
作用
public ActionResult VefifyAddingLocaleForPhoto(ArticleViewModel article)
{
//article.Locale == null for some reason.
//but article.Title isn't null, it contains the data
return RedirectToAction("AddingLocaleForPhotoSuccess", "adminka");
}
なぜarticle.Locale内のDropDownListの値を選択しましょうそれはヌルと等しく、それを修正する方法は?
ドロップダウンリストの名前をHTMLで確認してください –
名前はHTMLの "ロケール"です。 – Alexandre
"ID"がビューモデルに存在しないようです – Tassadaque