在我的RequestController中,我有两个同名的方法Create(),一个用于GET请求,另一个用于POST请求。 我希望在按钮中调用GET方法。 可以这样实现:
@Html.ActionLink("Create New", "Create")
但是在按钮中,它会调用POST的Create方法:
@using (Html.BeginForm("Create", "Request"))
{
<button type="submit">New Request</button>
}
RequestController 方法:
//
// GET: /Request/Create
public ActionResult Create()
{
ViewBag.ID = new SelectList(db.Expenses, "ID", "Department");
var destinations = from t in db.Typevalues
where t.Typeschema.SchemaCode == "CTY"
select t;
ViewBag.Destinations = destinations;
return View();
}
//
// POST: /Request/Create
[HttpPost]
public ActionResult Create(Request request)
{
if (ModelState.IsValid)
{
db.Requests.Add(request);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.ID = new SelectList(db.Expenses, "ID", "Department", request.ID);
return View(request);
}