0
我有和後控制器。 但通過httpPost的comtroller傳遞模型參數值爲null。 爲什麼我的httpPost模型參數值始終爲空?爲什麼httpPost模型始終爲空?
[HttpGet]
public ActionResult HireItem()
{
var HireItemListModel = new HireItemModel();
HireItemListModel = new HireItemModel()
{
first_name = Session["first_name"].ToString(),
middle_name = Session["middle_name"].ToString(),
last_name = Session["last_name"].ToString(),
ceremony_date = Session["ceremony_date"].ToString(),
};
var product = _productService.GetAllHireProducts();
if (product.Count != 0)
{
foreach (var proValue in product)
{
var productVarSeparateList = _productService.GetHireProductVariantsByProductIds(proValue.Id, false);
foreach (var HireProSep in productVarSeparateList)
{
var productVarSeparateModel = new HireItemModel.HireItemSeparatetModel()
{
pname = HireProSep.Name,
price =HireProSep.Price,
pId=HireProSep.Id,
};
HireItemListModel.HireItemSeparatetlist.Add(productVarSeparateModel);
}
var productVarSetList = _productService.GetHireProductVariantsByProductIds(proValue.Id, true);
foreach (var HireProset in productVarSetList)
{
var productVarListset = new HireItemModel.HireItemSetModel()
{
pname = HireProset.Name,
price = HireProset.Price,
pId = HireProset.Id,
};
HireItemListModel.HireItemSetList.Add(productVarListset);
}
}
}
return View(HireItemListModel);
}
此控制器HireItemModel模型參數值爲空。爲什麼??
[HttpPost,ActionName("HireItem")]
public ActionResult HireItem(string submitB, FormCollection formCollection, HireItemModel HireItemListModel)
{
var graduandList = _graduandService.GetGraduandBynameCeremony(HireItemListModel.ceremony_id, HireItemListModel.first_name, HireItemListModel.middle_name, HireItemListModel.last_name);
foreach (var graduand in graduandList)
{
graduand.height = HireItemListModel.height;
graduand.head_circumference = HireItemListModel.head_circumferenc;
_graduandService.Updategraduand(graduand);
}
這是我的看法。
@model HireItemModel
@using (Html.BeginForm())
{
<table >
<tr>
<td >
Ceremony :
</td>
<td>
Ceremony at @Model.ceremony_date
</td>
</tr>
<tr>
<td >
Name :
</td>
<td >
@Model.first_name @Model.middle_name @Model.last_name
</td>
</tr>
</table>
<div id="HItemType_1">
@Html.CheckBox("HItemType")
@*<input type="checkbox" name="test" value="test" id="HItemType" />*@
<label> Academic Dress Set</label>
</div>
<div id="HsetItem">
@Html.Partial("_LoadHireSetItem", @Model.HireItemSetList)
</div>
<div id="HseparateItem">
@Html.Partial("_LoadHireSeparateItem", @Model.HireItemSeparatetlist)
</div>
<table >
<tr>
<td colspan="2">
Please tell us your measurement:
</td>
</tr>
<tr>
<td >
Height (in cm):
</td>
<td>
@Html.EditorFor(model => model.height)
</td>
</tr>
<tr>
<td >
Head circumference (in cm):
</td>
<td >
@Html.EditorFor(model => model.head_circumferenc)
</td>
</tr>
</table>
<div>
<input class="productlistaddtocartbutton" type="submit" value="Add to cart" name="submitB" id="btnaddtocart"/>
</div>
}
謝謝。
你可以顯示你的視圖匹配HireItem行動。 – testCoder