jquery /view 中的 T4MVC url.action
这可能是可能的,也可能是不可能的(很可能在文档中,但我只是错过了)。
我如何使用 T4MVC 在我的视图中构造一个 Url.Action() ,这将允许我使用 jQuery 选择器。我一直在尝试以下操作(在我的javascript中)但没有成功:
function cancelHoldBooking() {
var url = '<%= Url.Action(MVC.FundProperty.CancelLock($("#propertyid").val())) %>';
// other code omitted for brevity
}
我能够成功地执行以下操作:
function cancelHoldBooking() {
var url = '<%= Url.Action("CancelLock", "FundProperty") %>';
url += "?id=" + $("#propertyid").val();
// other code omitted for brevity - in this case
// **I could of course have used the**:
// var params = {id: $('#propertyid').val()};
// **object**
}
我知道这将是答案到来时的“doh”时刻,但对于我的一生,我不能弄清楚这个!
干杯...
[编辑] - 我只想补充一点,如果我省略 MVC.FundProperty.CancelLock() id 参数并尝试通过 $ajax 调用发送 params 对象,那么编译器会抱怨缺少参数称呼。因此,我无法通过使用 CancelLock() 调用中没有参数的 $ajax params 对象进行调用来绕过 javascript mish-mash。令人沮丧:(
this may or may not be possible (and could well be in the docs but i've just missed it).
How do i structure a Url.Action() inside my view using T4MVC that will allow me to use jQuery selectors. I've been attempting the following (in my javascript) without success:
function cancelHoldBooking() {
var url = '<%= Url.Action(MVC.FundProperty.CancelLock($("#propertyid").val())) %>';
// other code omitted for brevity
}
i am able to successfully do the following:
function cancelHoldBooking() {
var url = '<%= Url.Action("CancelLock", "FundProperty") %>';
url += "?id=" + $("#propertyid").val();
// other code omitted for brevity - in this case
// **I could of course have used the**:
// var params = {id: $('#propertyid').val()};
// **object**
}
i know this will be a 'doh' moment when the answer arrives, but for the life of me, I can't figure this out!!
cheers...
[edit] - i would just add that if i omit the MVC.FundProperty.CancelLock() id paramater and attempt to just send the params object via the $ajax call, then the compiler complains about the missing parameter in the call. i can't therefore by-pass the javascript mish-mash by calling using the $ajax params object with no parameters inside the CancelLock() call. frustrating :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您试图以一种行不通的方式混合客户端和服务器代码。 :) <%= ... %>; block 是纯服务器端代码,因此它不能使用 JQuery 选择器。使用 T4MVC 可以做的最好的事情可能是这样的:
它仍然可以帮助您避免操作和控制器名称的文字字符串,但不会帮助您处理参数。
I think you're trying to mix client and server code in a way that just can't work. :) The <%= ... %> block is pure server side code, so it can't be using a JQuery selector. The best you can do with T4MVC might be something like:
It still saves you from literal strings for the action and controller name, but won't help you with the param.
您必须意识到
<%= ... %>
在服务器上处理,而$("#propertyid").val()
在服务器上运行调用函数cancelHoldBooking
时的客户端。解决您的问题的一种方法是:
You have to realize that
<%= ... %>
is processed on the server while$("#propertyid").val()
is run on the client when the functioncancelHoldBooking
is called.One way to solve your problem is this: