我有2意見。 ProductForm.aspx和Category.ascx。 CategoryForm是部分視圖。我使用EditorFor從ProductForm調用Category.ascx(model => model.Category)。在這個部分視圖中,有一個包含所有類別的DropdownlistFor。問題是特定產品類別的選定值。選定的值不起作用。Asp.Net mvc 2,DropDownListFor和編輯器模板。選定的值不d123
爲什麼?
以下是我在我的ProductForm
<div class="editor">
<div class="editor-label">
<%: Html.LabelFor(model => model.ProductInfo.ProductName) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.ProductInfo.ProductName)%>
<%: Html.ValidationMessageFor(model => model.ProductInfo.ProductName)%>
</div>
</div>
<%: Html.EditorFor(model => model.ProductInfo.Category, new { CategoryList = Model.CategoryList })%>
在Category.ascx
<div class="editor-field">
<%:Html.DropDownListFor(model => model.CategoryID, (IEnumerable<SelectListItem>)ViewData["CategoryList"])%>
</div>
這些是兩個單獨的形式?結果HTML是什麼樣的? – asfsadf 2010-09-24 18:27:57
是2個獨立的文件。 ProductForm.apsx是主視圖。 Category.ascx是由ProductForm調用的部分視圖在Category.ascx中,存在具有類別List的下拉列表。 – 2010-09-24 18:45:32
我沒有看到任何明顯的需要將這些分開。我將擁有一個包含Product對象的強類型視圖模型,以及CategoriesSelectList,它將以相同的形式出現。 – asfsadf 2010-09-24 18:56:11