我在ReceivingController
Index.cshtml
视图中有以下表单:
@using (Html.BeginForm("Details", "Grv"))
{
@Html.TextBox("grvNumber")
<input type="submit" value="search" />
}
根据我的理解,这应该重定向到我Details.cshtml
的{{1}},并传入GrvController
作为输入。
但是,当我提交表单时,我只是回到同一页面(grvNumber
)。
我怀疑这可能与我的路由有关,但我无法解决出错的问题。
Receiving/Index
routes.MapRoute(
name: "Default",
url: "",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Receiving",
url: "receiving",
defaults: new { controller = "Receiving", action = "Index" }
);
routes.MapRoute(
name: "ViewGrv",
url: "receiving/{grvNumber}",
defaults: new { controller = "Grv", action = "Details" }
);
routes.MapRoute(
name: "ViewPallet",
url: "receiving/{grvNumber}/{palletSequence}",
defaults: new { controller = "Pallet", action = "Details" }
);
我尝试将public class GrvController : Controller
{
public ActionResult Details(string grvNumber)
{
var access = new Access();
var grvData = access.GetGrvData(grvNumber);
var grv = new Grv(grvData);
Session["grv"] = grv;
return View(grv);
}
}
添加到[HttpPost]
GrvController
方法,并将Details
参数添加到FormMethod.post
,但行为完全相同。
如果我手动导航到网址BeginForm
,我会看到正确的../receiving/8
Grv
页面,但我需要在提交Details
表单后看到此页面。
我可以从设置断点看到提交表单永远不会发现Receiving
非常感谢任何建议,如果我可以发布更多详细信息,请告诉我。
答案 0 :(得分:2)
只需更改您的RouteConfig文件
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);