ASP.NET MVC3,模型内的集合使用 Forms GET 方法,并且对 URL/SEO 友好

发布于 2024-12-23 21:06:06 字数 1272 浏览 5 评论 0原文

让我描述一下我的代码,然后提出问题。

我有这样的课程

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温馨耳语 2024-12-30 21:06:07
http://localhost:3517/pl-PL/Places/Search?
fbool.Value=false&
fweek.Value=1&
fweek.Value=2&
ftxt.Value=23fasf&
ftxt.Value=assffg&

这在任何情况下都不起作用,因为您要发送具有相同名称的多个表单字段,因此它们需要有一个与之关联的索引。 IE

fweek[0].Value=1&fweek[1].Value =2

如果没有索引,你如何确定哪个 fweek 是哪个?

为什么不直接发布这个表格呢?

http://localhost:3517/pl-PL/Places/Search?
fbool.Value=false&
fweek.Value=1&
fweek.Value=2&
ftxt.Value=23fasf&
ftxt.Value=assffg&

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.

fweek[0].Value=1&fweek[1].Value =2

Without the index how can you determine which fweek is which?

Why not just post this form?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文