剃刀MVC3 +的jQuery + UrlAction + PartialViews [英] Razor mvc3 + jquery + UrlAction + PartialViews
问题描述
我有一个关于jQuery的+剃须刀的问题..我想建立使用带@ Url.Action和HTML属性剃刀将输入值的javascript变量。
像这样的:
I have a question about jQuery + Razor.. I want to build a javascript variable using razor with @Url.Action and the html attributes will be values of inputs. Like this:
VAR D1 = $('#D1)VAL();
结果 VAR D2 = $('#D2)VAL();
结果 VAR URL =@ Url.Action(链接,PartialAccount,新{BEGINDATE =D1,结束日期=D2})
结果 $(#链接)淡出(慢)负载(URL).fadeIn(慢);
我怎样才能做到这一点?
How can I do this?
是不是相同,以下?结果 VAR URL =/ PartialAccount /友情链接/ BEGINDATE =?+ D1 +&放大器;结束日期=+ D2;
Is it the same that below?
var url = "/PartialAccount/Links/?beginDate=" + d1 + "&endDate=" + d2;
推荐答案
您应该使用 负荷
方法提出InfernalBadger:
You should use the load
method as proposed by InfernalBadger:
load('@Url.Action("Links", "PartialAccount")', { beginDate: d1, endDate: d2})
因为这将带code在参数D1
和 D 2
正确。但是,只有当你可以通过这些参数作为查询字符串的一部分,而不是当他们应该是URL本身的一部分。
because this will encode the parameters in d1
and d2
correctly. But only if you can pass the parameters as part of the querystring, not when they should be a part of the url itself.
所以,如果你希望你的网址是你可以使用:
So you can use if you want your url to be:
/bar/foo?beginDate=1-1-2001&endDate=2-2-2001
(请注意,/的的日期将是连接codeD)
(note that the /'s in the date will be encoded)
如果您希望您的网址是你不能使用这样的:
You cannot use this if you want your url to be:
/bar/foo/1-1-2001/2-2-2001
的 @url
方法,与BEGINDATE和endData参数,无法正常工作,因为这是在服务器上执行,之前的页面发送到浏览器。
The @Url
method, with the beginDate and endData parameters, does not work, because this is executed on the server, before the page is send to the browser.
和使用 +
运营商的方法失败的用户在输入框特殊字符(如破折号/).
And your method by using the +
operator fails the user enters "special characters" in the input boxes (like dashes /).
这篇关于剃刀MVC3 +的jQuery + UrlAction + PartialViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!