In this code snippet
@using (Ajax.BeginForm("MyAction", "MyRouteValues", new AjaxOptions { OnSuccess = "myJSFunction(" + Model.IntegerParameter + ", '" + Model.StringParameter + "')" }))
Why is my Javascript correctly recognizing Model.IntegerParameter, but Model.StringParameter as null
? I am sure that he has data about it when I check the answer, and he shows it as
data-ajax-success="myJSFunction(111111, 'AAAAAA')"
My View model is really simple and looks like this:
public class MyViewModel { public int IntegerParameter { get; set; } public string StringParameter { get; set; } }
How to fix it?
Information added
I tried to change the second parameter to int, now it is not passed as null
, but 0
and still it shows in the answer in FireBug.
I added Html.Raw, but it still gets null
in Javascript.
Here is a screenshot of the real world about what I get in response to the console:

--------------- Another update ------------------
I tried all the sentences, but it seems like this is a BUG in MVC s # arp ? I tried in different projects, and on different PCs it is all the same for me. I noticed that this only happens if it comes from the model, it looks like it happens between the Javascript response, the value of the line is lost regardless of whether it is the first, second or any position in the parameter, but if I use solid coded value, for example:
myJSFunction(" + Model.IntegerParameter + ", 'AAAAAAAA')"
I get a successful result, also if I use jQuery, for example:
myJSFunction(" + Model.IntegerParameter + ", $('#SearchString').val())"
This also works, but if I pass in a model which is a string like
myJSFunction(" + Model.IntegerParameter + ", '" + Model.StringParameter + "')"
This does not work.
So, you want to see what really happens in the real world, where I took into account the proposals of @Darin and @Shark. Here is a screenshot:

As you can see in the answer, it is there, but when it is passed to Javascript, it is lost. Here is the real Javascript as well
displayResultsPopUpWindow: function (model) { var postData = { transactionId: model.transactionId, searchString: model.searchString }; $.post("/Invoicing/GetSearchResults", postData, function (data) { WindowHelper.displayWindow("Add Airline Transaction", "<div id='matchBookingResults'>" + unescape(data.viewHtml) + "</div>", 640, 500); }); },