MVC 2 表单 GET 的路由?还是邮寄?
我有一个带有单个文本框和一个提交按钮的小表单。
using (Html.BeginForm("Index", "Tag", FormMethod.Post)
在我的标签控制器中,我有一个如下所示的方法:
public ActionResult Index(string tagText)
我试图首先弄清楚如何路由它,因此生成的 URL 将如下所示:
http://mydomain.com/Tag/tagText
我想我也想让这个控制器处理这些类型的 URL 并返回我的视图,就像从表单发布一样我已经在上面展示了。我是新手,所以感谢您的帮助!
I have a small form with a single textbox and a submit button.
using (Html.BeginForm("Index", "Tag", FormMethod.Post)
In my tag controller i have a method that looks like:
public ActionResult Index(string tagText)
I'm trying to figure out first how to route this so the resulting URL will look like:
http://mydomain.com/Tag/tagText
And i guess i would also like to have this controller handle those types of URLs and return my view the same as if it was posted from the form i've shown above. I am a newb so thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从我看到的你的帖子来看,你希望用户最终到达一个 URL,其中最后一位是他们实际放入文本框中的内容。为此,您需要 ActionResult 发送
return RedirectToAction("Tag", new {tagText=tagText} )
,然后拥有映射“/Tag/{tagText}”的路由。
From what I can see of your post you want the user to end up at a URL where the last bit is what they actually put in a text box. To do this you need your ActionResult to send
return RedirectToAction("Tag", new {tagText=tagText} )
then have a route which maps "/Tag/{tagText}".