3 回答

TA貢獻1775條經(jīng)驗 獲得超11個贊
您需要將要發(fā)布的數(shù)據(jù)包裝到表單中:
@using (Html.BeginForm("Search", "YOUR CONTROLLER", FormMethod.Post)) {
<div class="form-group">
@Html.LabelFor(model => model.BudgetCodeID, "BudgetCode:", new { @class = "control-label" })
@Html.DropDownListFor(m => m.BudgetCodeID, (SelectList)ViewBag.BudgetsList, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.BudgetCodeID, "", new { @class = "text-danger" })
</div>
}
您的 POST 操作需要接受您發(fā)布的模型:
public ActionResult Post(MyModel model)
{
//call a service to save info to database
}

TA貢獻1982條經(jīng)驗 獲得超2個贊
我發(fā)現(xiàn)從控制器中刪除異步確實會將整數(shù)回發(fā)到表中。
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ClinicalAssetID,AssetTypeID,ProductID,ManufacturerID,ModelID,SupplierID,SerialNo,PurchaseDate,PoNo,Costing,TeamID,StaffID,WarrantyEndDate,InspectionDate,InspectionOutcome,InspectionDocumnets,InspectionDueDate, BudgetCodeID")] ClinicalAsset clinicalAsset)
{
if (ModelState.IsValid)
{
db.ClinicalAssets.Add(clinicalAsset);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.AssetTypeID = new SelectList(db.AssetTypes, "AssetTypeID", "AssetTypeName", clinicalAsset.AssetTypeID);
ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", clinicalAsset.ProductID);
ViewBag.ModelID = new SelectList(db.Models, "ModelID", "ModelName", clinicalAsset.ModelID);
ViewBag.ManufacturerID = new SelectList(db.Manufacturers, "ManufacturerID", "ManufacturerName", clinicalAsset.ManufacturerID);
ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", clinicalAsset.SupplierID);
ViewBag.TeamID = new SelectList(db.Teams, "TeamID", "TeamName", clinicalAsset.TeamID);
ViewBag.StaffID = new SelectList(db.Staffs, "StaffID", "StaffName", clinicalAsset.StaffID);
ViewBag.InspectionOutcomeID = new SelectList(db.InspectionOutcomes, "InspectionOutcomeID", "InspectionOutcomeResult", clinicalAsset.InspectionOutcomeID);
var Budgets = (from m in db.BudgetCodes
select new SelectListItem
{
Text = m.Code + " | " + m.BudgetCodeName,
Value = m.BudgetCodeID.ToString()
});
ViewBag.BudgetsList = new SelectList(Budgets, "Value", "Text");
return View(clinicalAsset);
}

TA貢獻1860條經(jīng)驗 獲得超8個贊
在你的代碼中。您在操作方法中發(fā)送的數(shù)據(jù)屬于 POST 類型。
[HttpPost]
[ValidateAntiForgeryToken] 公共異步任務(wù)創(chuàng)建()
您必須在視圖頁面中定義“FormMethod”。例如:
@using (Html.BeginForm("ActionMethod 名稱", "控制器名稱", FormMethod.Post)) {
} ` 我希望這對我有幫助。
- 3 回答
- 0 關(guān)注
- 133 瀏覽
添加回答
舉報