具有动态路由的 MVC Post
我创建了一个路由结构,而 URL 的操作部分充当动态处理程序,用于选择特定用户创建的系统名称。即
http://mysite.com/Systems/[SystemName]/Configure,其中[SystemName] 指定他们要配置的系统的名称。
路由系统的方法如下:
public ActionResult Index(string systemName, string systemAction)
{
ViewData["system"] = _repository.GetSystem(systemName);
if (systemAction != "")
{
return View(systemAction);
}
else
{
// No Id specified. Go to system selection.
return View("System");
}
}
上述方法将系统设置为配置并路由到显示视图和表单等待值的静态方法。
我的问题是,当我创建配置视图时,提交表单时我会丢失发布的值,因为它会路由回上面的索引控制器。当点击上面的索引控制器时,如何确定数据是否正在发布,以便我可以做出决定?
谢谢! 乔治
I've created a routing structure whereas the action part of the URL serves as a dynamic handler for picking a specific user created system name. i.e.
http://mysite.com/Systems/[SystemName]/Configure, where [SystemName] designates the name of the system they would like to configure.
The method that routes the system is the following:
public ActionResult Index(string systemName, string systemAction)
{
ViewData["system"] = _repository.GetSystem(systemName);
if (systemAction != "")
{
return View(systemAction);
}
else
{
// No Id specified. Go to system selection.
return View("System");
}
}
The above method sets the system to configure and routes to a static method where the view is displayed and a form awaits values.
The question I have is that when I create my configuration view, I lose my posted values when the form is submitted because it routes back to the above Index controller. How can I determine if data is being posted when hitting my above Index controller so that I can make a decision?
Thanks!
George
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样注释处理 POST 的控制器方法:
您可以在控制器中使用不同的方法来处理 GET:
请注意,虽然我在每种情况下都复制了相同的方法和参数,但第二个方法的签名(参数和类型)必须不同,以便这两种方法不会产生歧义。
NerdDinner 教程有这样的示例。
Annotate the controller method that handles the POST like this:
You can have a different method in your controller that handles the GETs:
Note that, although I have copied the same method and parameters in each case, the signature for the second method (parameters and types) will have to be different, so that the two methods are not ambiguous.
The NerdDinner tutorial has examples of this.