来自GET表单的MVC 2路由?还是POST?

时间:2010-10-18 22:11:26

标签: model-view-controller asp.net-mvc-2 routing asp.net-mvc-routing

我有一个带有单个文本框和提交按钮的小表单。

using (Html.BeginForm("Index", "Tag", FormMethod.Post)

在我的标签控制器中,我有一个看起来像这样的方法:

public ActionResult Index(string tagText)

我首先要弄清楚如何路由这个,以便生成的URL看起来像:

http://mydomain.com/Tag/tagText

我想我也想让这个控制器处理这些类型的URL并返回我的视图,就像它从我上面显示的表单中发布一样。我是新手,所以感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

从我所看到的帖子中,您希望用户最终得到一个URL,其中最后一位是他们实际放在文本框中的内容。为此,您需要ActionResult发送

return RedirectToAction("Tag", new {tagText=tagText} )

然后有一个映射“/ Tag / {tagText}”的路线。