Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Url.Action adding "amp;" between parameters creating nulls in the controller?

I am trying to send through multiple parameters through the 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");

enter image description here

As you can see there is a vin number passed through, but its a null in my controller.

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;.

like image 457
Pomster Avatar asked Nov 02 '15 13:11

Pomster


1 Answers

Url.Action isn't the problem - it's how you use it.

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 &amp;. 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="@...">).

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.Raw(Url.Action("Test", new { arg1 = "Hi!", arg2 = "there." }))
like image 121
Luaan Avatar answered Nov 08 '22 05:11

Luaan