私はASP.NET MVC4 Webアプリに取り組んでおり、URLに を含むGETリクエストを処理するためのコントローラーメソッドidがあります...
[PortalAuthorization]
public ActionResult View(int id)
{
// get the individual ftp log
PortalFTPLog log = PortalFTPLogs.Get(id);
if (log == null)
{
TempData["Error"] = "The provided ftp log id does not exist.";
return RedirectToAction("Index");
}
// get the available matters to tie uploads to
ViewBag.matters = PortalMatters.Get();
return View(log);
}
このコントローラ メソッドの私の見解では、フォームを更新できるようPOSTに、同じ URL に戻したいと考えています。のような URL ですfoo.com\items\1。それが上記の関数が処理するものです。
POSTただし、パラメーターを必要とする関数の要求を処理する関数を作成するにはどうすればよいでしょうか? 前のPOSTハンドラーで FormsCollection パラメーターを作成しましたが、この関数のパラメーター リストに追加すると、パラメーターidが null になります。
[HttpPost]
[PortalAuthorization]
public ActionResult View(FormCollection collection, int id)
{
PortalFTPLog log = PortalFTPLogs.Get(id);
if (log == null)
{
TempData["Error"] = "The provided ftp log id does not exist.";
return RedirectToAction("Index");
}
// update the matter id and save to database
log.Matter = Convert.ToInt32(collection.Get("matter"));
log.Save();
TempData["Notice"] = "The FTP log meta data has been updated.";
return RedirectToAction("View", new { id = id });
}