I am trying to send through multiple parameters through the Url.Action.
我试图通过Url.Action发送多个参数。
$('#dialog').dialog({
autoOpen: false,
width: 850,
height: 420,
resizable: false,
title: 'Vehicle details',
modal: true,
open: function (event, ui) {
$(this).load("@Url.Action("LightStoneRequest", new { registrationNumber = Model.VehicleRegistration, vinNumber = Model.vVinNumber })");
},
buttons: {
"Close": function () {
$(this).dialog("close");
}
}
});
During run time it looks as follows:
在运行时,它看起来如下:
$(this).load("/APQuotes/LightStoneRequest?registrationNumber=TE5TGP&vinNumber=VINTEST44889856");
As you can see there is a vin number passed through, but its a null in my controller.
正如你所看到的,有一个vin号通过,但它在我的控制器中为null。
Here is my modal.
这是我的模态。
public partial class LightStoneRequest
{
public LightStoneRequest()
{
this.LightStoneDataFields = new HashSet<LightStoneDataField>();
}
public int LightStoneRequestId { get; set; }
public string RegistrationNumber { get; set; }
public string VinNumber { get; set; }
public virtual ICollection<LightStoneDataField> LightStoneDataFields { get; set; }
}
if i remove the amp; it works, but the URL.Action adds the amp;.
如果我删除放大器;它工作,但URL.Action添加了amp;。
1 个解决方案
#1
8
Url.Action
isn't the problem - it's how you use it.
Url.Action不是问题 - 这就是你如何使用它。
You're using @
- this is used for inlining the results of a piece of server-side code in a (X)HTML page. In a (X)HTML page, entities must be properly encoded, turning your &
into a &
. This is the exact correct behaviour - that's how it's supposed to be inlined in either text or an attribute, for example (which is why you use it in e.g. <a href="@...">
).
您正在使用@ - 这用于在(X)HTML页面中内联一段服务器端代码的结果。在(X)HTML页面中,必须正确编码实体,将您的&转换为& ;.这是完全正确的行为 - 例如,它应该以文本或属性的形式进行内联(这就是您在例如中使用它的原因)。
However, you're trying to inline the raw value, rather than the encoded value - because you're not trying to emit HTML, you're emitting raw text. Html.Raw
does just that:
但是,您尝试内联原始值而不是编码值 - 因为您没有尝试发出HTML,而是发送原始文本。 Html.Raw就是这么做的:
@Html.Raw(Url.Action("Test", new { arg1 = "Hi!", arg2 = "there." }))
#1
8
Url.Action
isn't the problem - it's how you use it.
Url.Action不是问题 - 这就是你如何使用它。
You're using @
- this is used for inlining the results of a piece of server-side code in a (X)HTML page. In a (X)HTML page, entities must be properly encoded, turning your &
into a &
. This is the exact correct behaviour - that's how it's supposed to be inlined in either text or an attribute, for example (which is why you use it in e.g. <a href="@...">
).
您正在使用@ - 这用于在(X)HTML页面中内联一段服务器端代码的结果。在(X)HTML页面中,必须正确编码实体,将您的&转换为& ;.这是完全正确的行为 - 例如,它应该以文本或属性的形式进行内联(这就是您在例如中使用它的原因)。
However, you're trying to inline the raw value, rather than the encoded value - because you're not trying to emit HTML, you're emitting raw text. Html.Raw
does just that:
但是,您尝试内联原始值而不是编码值 - 因为您没有尝试发出HTML,而是发送原始文本。 Html.Raw就是这么做的:
@Html.Raw(Url.Action("Test", new { arg1 = "Hi!", arg2 = "there." }))