Thursday, 22 August 2013

how to map an mvc action parameter with a value of null correctly

how to map an mvc action parameter with a value of null correctly

I'm posting a serialized string to an MVC action in C# where an empty
parameter (i.e. &test=&another=10) maps to a value of 0.0. I need it to
evaluate to null. Many thanks,
The jquery is below:
$.ajax({
type: method,
url: url,
data: data,
dataType: 'json',
success: settings.success,
error: settings.error,
async: !options.sync
});
MVC Controller
[AcceptVerbs(HttpVerbs.Post)]
[NoCache]
[JsonContractExceptionFilter]
public ActionResult Save(Query query, ViewModel data)
{
data.test == 0.0 // should be null
Query
public double? Test
{
get { return obj.RateValue; }
set { obj.RateValue = value; }
}

No comments:

Post a Comment