我創建了一個應用程序,允許我記錄食譜。我試圖創建一個視圖,允許我添加配方的基礎知識,例如食譜名稱,配方日期,在&使用的成分烹飪溫度。我的控制器viewmodel沒有填充我的動態視圖模型
我正在創建一個視圖,其中包含一些jquery加載部分視圖clientside。
後在即時通訊有幾個麻煩試圖從已使用jquery加載的部分視圖獲取值。
一個砍下我的主要觀點的版本看起來像(我最初想1個的局部視圖加載)
<div id="ingredients">
@{ Html.RenderPartial("_AddIngredient", new IngredientViewModel()); }
</div>
<script type="text/javascript">
$(document).ready(function() {
var dest = $("#ingredients");
$("#add-ingredient").click(function() {
loadPartial();
});
function loadPartial() {
$.get("/Recipe/AddIngredient", {}, function (data) { $('#ingredients').append(data); }, "html");
};
});
</script>
我的部分觀點貌似
<div class="ingredient-name">
@Html.LabelFor(x => Model.IngredientModel.IngredientName)
@Html.TextBoxFor(x => Model.IngredientModel.IngredientName)
</div>
<div class="ingredient-measurementamount">
@Html.LabelFor(x => Model.MeasurementAmount)
@Html.TextBoxFor(x => Model.MeasurementAmount)
</div>
<div class="ingredient-measurementtype">
@Html.LabelFor(x => Model.MeasurementType)
@Html.TextBoxFor(x => Model.MeasurementType)
</div>
控制器後
[HttpPost]
public ActionResult Create(RecipeViewModel vm,IEnumerable<string>IngredientName, IEnumerable<string> MeasurementAmount, IEnumerable<string> MeasurementType)
{
最後,我的viewmodel看起來像
public class IngredientViewModel
{
public RecipeModel RecipeModel { get; set; }
public IEnumerable<IngredientModel> Ingredients { get; set; }
}
我的控制器是很醜陋......使用Inumerble以獲取MeasurementAmount & MeasurementType(IngredientName始終返回null)值IM,理想的情況是我想對httppost成分將與所有的填充上我將能夠配料填充
我需要做什麼才能從我的局部視圖獲取值到我的控制器?
歡呼謝恩。該工具包非常酷! –