3 回答
TA贡献1775条经验 获得超11个赞
您需要将要发布的数据包装到表单中:
@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 操作需要接受您发布的模型:
public ActionResult Post(MyModel model)
{
//call a service to save info to database
}
TA贡献1982条经验 获得超2个赞
我发现从控制器中删除异步确实会将整数回发到表中。
[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条经验 获得超8个赞
在你的代码中。您在操作方法中发送的数据属于 POST 类型。
[HttpPost]
[ValidateAntiForgeryToken] 公共异步任务创建()
您必须在视图页面中定义“FormMethod”。例如:
@using (Html.BeginForm("ActionMethod 名称", "控制器名称", FormMethod.Post)) {
} ` 我希望这对我有帮助。
- 3 回答
- 0 关注
- 88 浏览
添加回答
举报