A JsonResult is calling me back an anonymous type. I can use the alert function to check it is correctly received client side, but impossible to fill a textbox value with this result. While I can fill a textarea value, I tried to parse the result (the textbox are bound to my model view, to a float and a int data type, but I don't think its because of this type).
This is my code :
$.ajax({
type: "POST",
url: "/MyCalledFunction/?arg1=" + $("#FK_ARG").val(), datatype: "json",
success: function(data) {
if (data) {
// my return result if an anymous type
var price = data.price;
var NbDefaultDaysNumber = data.NbDefaultDaysNumber;
alert(price);// display the msgbox with '100'
$("#MY_PRICE").html(price);// textbox type value -> failed
$("#DEFAULT_DAYS").html(NbDefaultDaysNumber); // textbox type value -> failed
$("#ANOTHER_AREA").html(NbDefaultDaysNumber);// text area property value... -> works
}
}
});
public JsonResult MyCalledFunction(string arg1)
{
// some unintersting code...
var myReturnJSon = new {price = 100,
DEFAULT_DAYS = 10};
return Json(myReturnJSon);
}
Im sure it's a stupid question of binding with some text parameters somewhere. Any idea?
For a textbox (by which I assume you mean an <input>
with type="text"
, you should be using val()
and not html()
$("#DEFAULT_DAYS").val(NbDefaultDaysNumber);