I am trying to post data in JSON format to a .NET MVC Controller like this.
$.ajax({
type: 'POST',
url: 'http://mvc.tester.local/Home/NameConverter',
data: JSON.stringify({ convertermodel.InputName: obj.currentTarget.value }),
contentType: 'application/json'
});
But Javascript complains about the JSON.Stringify() bit.
The convertermodel.InputName to be exact.
The thing is I actually need this JSON data name to be that way i.e. have the same name as a property in my model; in order to take advantage of reflection for automatic binding.
This is my model:
public class NamesViewModel
{
public NameConverterModel convertermodel = new NameConverterModel();
}
and the sub Class
public class NameConverterModel
{
private string _inputName = "";
public string InputName
{
get { return _inputName; }
set { _inputName = value; }
}
}
How can I solve this please ?
I hope I am clear enough.