0

I have a JQuery Ajax call that posts some data (Json) to a MVC Controller. Basically in my method I have

public JsonResult Save()
{
    TryUpdateModel(MyModel)
    ...
}

What I want to do is change some values in the posted Ajax data, before calling TryUpdateModel(). I've tried numerous ways including

ViewData.ModelState.SetModelValue("MyTextBox", new ValueProviderResult("Some string", string.Empty, new System.Globalization.CultureInfo("en-US")));

Everything time it appears that the values I'm changing aren't being updated. Any ideas where I'm going wrong ?

neildt
  • 5,101
  • 10
  • 56
  • 107

1 Answers1

1

Guess I'm still to new to post against your question, but what is your posted object? Model, string, etc. You left some detail out of the code.

Without more detail, this Posting JSON data via jQuery to ASP .NET MVC 4 controller action may help

Community
  • 1
  • 1
Stinky Towel
  • 768
  • 6
  • 26
  • The posted data is Json. – neildt Oct 18 '13 at 13:52
  • Does your JSON data map to an object/model? Why not change it then? – Stinky Towel Oct 22 '13 at 14:41
  • It does, but the problem I'm having is I need to modify the data before it gets to the model, ie when TryUpdateModel is called (which I assume populates the model) – neildt Oct 22 '13 at 20:32
  • The JSON needs to map to some type coming in. Are you wanting to work with it as a string, manipulate some key/value pairs then map to your model? Perhaps an actionfilterattribue as shown in the answer in this SO post [link](http://stackoverflow.com/questions/560575/asp-net-mvc-how-to-pass-json-object-from-view-to-controller-as-parameter) will help. – Stinky Towel Oct 23 '13 at 13:30