我决定用 Areas 组织我的应用程序,现在有些表单无法提交。
控制器
public class SoftwareInfoController{
public ActionResult Index(){...}
public ActionResult New(){...}
[HttpPost]
public ActionResult Save(SoftwareInfoViewModel viewModel){...}
}
我可以像这样访问视图,“包装”是一个区域
webpage.com/Packaging/SoftwareInfo/Index
webpage.com/Packaging/SoftwareInfo/New
Index 和 New 方法都可以正常工作。但我无法提交表格。
edit.cshtml
@model SoftwareInfoViewModel
...
@using (Html.BeginForm("Save","SoftwareInfo")){...} // does nothing
@using (Html.BeginForm("Save","SoftwareInfo", FormMethod.Post)){...} // does nothing
@using (Html.BeginForm("Save","SoftwareInfo", new {Area = "Packaging" })) {...}// does nothing
路由
context.MapRoute(
name: "Packaging_default",
url: "Packaging/{controller}/{action}/{id}",
defaults: new { controller = "Editor", action = "Index", id =UrlParameter.Optional },
namespaces: new[] { "WebApp.Areas.Packaging.Controllers" }
);