考慮以下模型:ASP.NET MVC - 使用模型屬性作爲窗體,我如何發佈到行動?
public class BandProfileModel
{
public BandModel Band { get; set; }
public IEnumerable<Relationship> Requests { get; set; }
}
和下面的形式:
<% using (Html.BeginForm()) { %>
<%: Html.EditorFor(m => m.Band) %>
<input type="submit" value="Save Band" />
<% } %>
哪些職位以下行動:
public ActionResult EditPost(BandProfileModel m, string band)
{
// stuff is done here, but m is null?
return View(m);
}
基本上,我只有在我的模型中的一個屬性在表單中使用。 BandProfleModel中的其他屬性僅用於UI中的其他數據。我試圖更新Band屬性,但對於每個帖子,參數「m」始終爲空(具體而言,.Band屬性爲空)。
它發佈的行爲很好,所以它不是我的路線問題。只是數據爲空。
領域的ID和名稱屬性BAND_whatever和Band.whatever(無論是樂隊的一個屬性),所以它似乎將工作...
我在做什麼錯?我怎樣才能使用一個屬性作爲表單的一部分,回傳,並通過模型聯編程序爲我的BandProfileModel屬性在動作中填充值?謝謝。