I have a model that I send in my view. Since this model has many complex objects, I use After editing my model (creating new item, updating existing items, and changing objects from another location), I am posting it to the controller using the following code : <("Update", "Editor")%> ', Type: "post", data type:' jason ', data: JSON.stringify ({aModel: model}), success: function (data) {}}) (function (result) {});} ); var model = & lt;% = Html.Raw (Json.Encode (model))% & gt; to display all the jQuery methods for all the codes. ; A global variable
Getting it into my controller:
[HTTP post] Public Action Result Update (MyMoldEmodel) {ModelState.Clear () aModel. Execute (); See Return ("Path / in / View"); }
When I check the results of JSON.stringify ({aModel: model}), then I can see my changes. However, the object
AModel
does not receive this change
I tried to clear the ModelState, I tried to avoid caching, I tried to copy the existing element from the model and Tried to change its values, instead of pushing into a Jason array, come a new one Instead of creating the system, but did not work any of these.
My model is like the following:
Public class MyModel {public dictionary & lt; String, list & gt; Items & gt; & Gt; Item {get; Set; } Public listing & lt; Side effects & gt; Properties (get; set;}}
Can the dictionary model binding cause problems? Suppose that this is a model byteing problem.
Any thoughts?
1 edit
Based on the comments, I thought the problem was complex type items
and ItemProperty
. I tried to use parameterized constructors and public sets in the Id
attribute, but this The problem is not to solve the problem.
Here are the squares:
public class items {public const string CONST = "value"; private sub-esteem ASBITM; public list & Lt; SubItem & gt; Sub-item {get; set;} public string id {get; private set;} public string name {get; set;} public string help {get; set;} public date time { Get; set;} public item (string AID) {id = ii} D;}} Public class subitem {public list> item type> properties = new list & lt; Item type & gt; (); Public string id {get; Private set; } Public string subtitles {get; Set; } Get Public Bowl Subtitle {Get; Set; } Public bool visible {get; Set; } Public MyEnumType type {get; Set; } Public sub-id (string AID) {id = an ID; }} Public class ItemProperty {public string id {get; Private set; } Public string title {get; Set; } Public string path {get; Set; } Public bool visible {get; Set; } Public MyAction CustomAction = New MyAction (); Public ID (String AID) {ID = an ID; }} Public class MyAction {public string ActionName {get; Set; }}
and the serial model while posting. The only thing changed from the original model is name
property:
"{" item ": {" ITEM1 ": [{" Sub Ets ": [" True, "other", "visible": true, "myname type": 0}], "help": "other", "subtitles": "other", "subtitles are inaccessible" "," Name ":" A name added to send to the controller "," id ":" ITEM1 "," time ":" / date (-62135578800000) / "}, ...
That's because you're posting a string. > JSON Post the actual object as meaningless. By default, jQuery will encode it and send it in a format that can be parsed by your action. As you are still managing it, you are just posting a string The modelbender is a
MyModel
example, but becauseMyModel
is a class-type, string-tie is not on it, it fails.$. Ajax ({url: '& lt;% = Url.Action ("Update Data type: 'Jason', data: {aModel: model}, success: function (data) {}}) done (function (result) {});
No comments:
Post a Comment