ASP.NET MVC 路由

发布于 2024-10-06 00:21:49 字数 740 浏览 4 评论 0原文

我有一个要求,让用户使用友好的网址搜索属性。我创建了这条路线

routes.MapRoute(
        "Search", // Route name
          "{controller}/{action}/refno/{refno}/status/{status}/proptype/{proptype}/locality/{locality}/pricefrom/{pricefrom}/priceto/{priceto}", // URL with parameters
         new { controller = "Property", action = "Search", refno = "0", proptype = "ANY TYPE", status = "ANY STATUS", locality = "ANY LOCALITY", pricefrom = "0", priceto = "NO LIMIT" }

,请求 action="/Property/Search/refno/0/status/Converted/proptype/Airspace/locality/Any locality/pricefrom/0/priceto/No limit" 实际上正确调用了该路线。

然而有一点奇怪。当显示带有结果的搜索表单时,JavaScript 脚本标记将被忽略,因此某些通过 JavaScript 填充的下拉列表不会被填充。我的印象是,我创建的路由实际上阻止了我在母版页中的脚本标记。

有人可以帮助我吗?

I have a requirement which lets the user search for properties using friendly urls. I created this route

routes.MapRoute(
        "Search", // Route name
          "{controller}/{action}/refno/{refno}/status/{status}/proptype/{proptype}/locality/{locality}/pricefrom/{pricefrom}/priceto/{priceto}", // URL with parameters
         new { controller = "Property", action = "Search", refno = "0", proptype = "ANY TYPE", status = "ANY STATUS", locality = "ANY LOCALITY", pricefrom = "0", priceto = "NO LIMIT" }

and the request action="/Property/Search/refno/0/status/Converted/proptype/Airspace/locality/Any locality/pricefrom/0/priceto/No limit" actually calls the route correctly.

However there is something strange. When the search form with the results is shown the javascript script tags are being ignored and therefore some dropdowns which are filled through javascript are not being filled. I am of the impression that the routing which I have created actually blocks the script tags which I have in the master page.

Can someone help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

她如夕阳 2024-10-13 00:21:49

您的浏览器正在查找与 URL 相关的 .js 文件。确保您的脚本标签使用 Url.Content("~/somepath/file.js") 引用您的 .js 文件。

如果这不是问题,请确保页面上的某个位置不存在阻止其余部分执行的 JavaScript 错误。

Your browser is looking for the .js files relative to the URL. Make sure your script tags are referencing your .js files with Url.Content("~/somepath/file.js").

If that isn't the problem, make sure that there is not a javascript error someplace on your page that is blocking the rest from executing.

无远思近则忧 2024-10-13 00:21:49

你好,
首先感谢您的回复。肯定不会有 JS 错误,因为 JS 文件是在始终有效的用户控件上调用的。

我刚刚在 IIS Express 上运行该网站来跟踪该网站。似乎正在完成正确的帖子,但随后在结果表单上,js 文件被请求为搜索帖子和 js 文件。

例如......如果我发布到 /search/properties/refno/5/propstatus/finished,首先会发布正确的帖子,然后当呈现结果表单时,将对 /search/properties/ 执行 GET 操作refno/5/propstatus/finished/jquery/jquery0.5.2.min.js 这是不正确的。

让您了解我在做什么。这是用户控件。我只发布表单操作。现在我发布到静态路由只是为了测试。

action="/Property/Search/refno/0/status/Converted/proptype/Airspace/locality/Any locality/pricefrom/0/priceto/No limit" method="post">

这是母版页标题 js 文件

 <script type="text/javascript" src="../../Scripts/jquery/001-jquery-1.4.2.min.js"></script>
 <script type="text/javascript" src="../../Scripts/jquery/jquery.lightbox-0.5.min.js"></script>
 <script type="text/javascript" src="../../Scripts/utils/jquery.markaf.mvc.utils.debug.js"></script>
 <script type="text/javascript" src="../../Scripts/ui/ui.search.debug.js"></script>

这是控制器发布到的搜索表单

搜索

<% foreach (模型中的 var item)
{%>

参考编号:<%:item.RefNo %>

<%:项目.描述%>

价格:<%:item.Price.ToString("c") %>

“>阅读更多...

<%} %>

HI,
First of all thanks for the reply. There are no JS errors for sure sinc the JS file is being called on a user control which always works.

I just ran the website on IIS express to trace the website. It seems that the correct post is being done, but then on the results form the js files are being requested as the search post and the js file.

For example.... if I post to /search/properties/refno/5/propstatus/finished, a correct post is first made, then when the results form is being rendered a GET action is being done to /search/properties/refno/5/propstatus/finished/jquery/jquery0.5.2.min.js which is incorrect.

To give you an idea of what I am doing. This is the user control. I am only posting the form action. Right now I am posting to a static route just to test.

action="/Property/Search/refno/0/status/Converted/proptype/Airspace/locality/Any locality/pricefrom/0/priceto/No limit" method="post">

This is the master page header js files

 <script type="text/javascript" src="../../Scripts/jquery/001-jquery-1.4.2.min.js"></script>
 <script type="text/javascript" src="../../Scripts/jquery/jquery.lightbox-0.5.min.js"></script>
 <script type="text/javascript" src="../../Scripts/utils/jquery.markaf.mvc.utils.debug.js"></script>
 <script type="text/javascript" src="../../Scripts/ui/ui.search.debug.js"></script>

And this is the search form which the controller posts to

Search

<% foreach (var item in Model)
{ %>

Ref No : <%:item.RefNo %>

<%:item.Description %>

Price : <%:item.Price.ToString("c") %>

">Read more...

<%} %>

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