ASP.NET MVC3,模型内的集合使用 Forms GET 方法,并且对 URL/SEO 友好
让我描述一下我的代码,然后提出问题。
我有这样的课程
public class MyModel
{
public virtual ICollection<SomeObject> fweek { get; set; }
public virtual ICollection<SomeObject> ftxt { get; set; }
public virtual ICollection<SomeObject> fbool { get; set; }
}
然后我正在为这样的模型创建编辑器:
@model MyModel
@using(Html.BeginForm("SomeAction", "SomeController", FormMethod.GET))
{
@Html.EditorFor(m => m.fweek)
@Html.EditorFor(m => m.ftxt)
@Html.EditorFor(m => m.fbool)
<input type="submit" value="Submit" />
}
如果我提交表单作为结果,我会被重定向到类似的 URL:
http://localhost:3517/pl-PL/Places/Search?
fbool%5B0%5D.Value=false&
fweek%5B0%5D.Value=1&
fweek%5B1%5D.Value=2&
ftxt%5B0%5D.Value=23fasf&
ftxt%5B1%5D.Value=assffg&
问题是: 是否可以重写此类 URL(尤其是 %5B 和 %5D 序列)以变得更加 SEO/用户友好? 假设这个示例 URL 可能如下所示:
http://localhost:3517/pl-PL/Places/Search?
fbool.Value=false&
fweek.Value=1&
fweek.Value=2&
ftxt.Value=23fasf&
ftxt.Value=assffg&
感谢您的帮助。 问候。
Let me describe the code I have and then I ask the question.
I have such class
public class MyModel
{
public virtual ICollection<SomeObject> fweek { get; set; }
public virtual ICollection<SomeObject> ftxt { get; set; }
public virtual ICollection<SomeObject> fbool { get; set; }
}
Then I'm creating editor for such model:
@model MyModel
@using(Html.BeginForm("SomeAction", "SomeController", FormMethod.GET))
{
@Html.EditorFor(m => m.fweek)
@Html.EditorFor(m => m.ftxt)
@Html.EditorFor(m => m.fbool)
<input type="submit" value="Submit" />
}
If I submit my form as a result I'm redirected to similar URL:
http://localhost:3517/pl-PL/Places/Search?
fbool%5B0%5D.Value=false&
fweek%5B0%5D.Value=1&
fweek%5B1%5D.Value=2&
ftxt%5B0%5D.Value=23fasf&
ftxt%5B1%5D.Value=assffg&
The question is:
Is it possible to rewrite such URL (especially %5B and %5D sequences) to become more SEO/User friendly?
Lets say this example URL may look like this:
http://localhost:3517/pl-PL/Places/Search?
fbool.Value=false&
fweek.Value=1&
fweek.Value=2&
ftxt.Value=23fasf&
ftxt.Value=assffg&
Thank you for any help.
Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这在任何情况下都不起作用,因为您要发送具有相同名称的多个表单字段,因此它们需要有一个与之关联的索引。 IE
如果没有索引,你如何确定哪个
fweek
是哪个?为什么不直接发布这个表格呢?
This would not work in any scenario because you're sending multiple form fields with the same name, so they need to have an index associated with them. I.E.
Without the index how can you determine which
fweek
is which?Why not just post this form?