model view controller - MVC 3: Why is jquery form.serialize not picking up all the controls in my form? -
After
I am trying to create a situation where if a list of text items has an "edit" button On a user clicks, he can edit that item I am trying to return after the "edit" button using ajax
Here is my ajax code:.
$ post (edit / edit request $ ('id' = 'editItem "]. Live (" click ", (function () {var id = $ (this ) .attr ('id'); var section = id.split ('_'); if (sections.length == 2) {var itemID = squares [1]; var divID = "message_" + itemID; var form = $ ("# NewsForm"); $ .post (form.attr ("verb"), form.serialize (), function (data) {$ ("#" + divid) .html (data);}); } Return false;}));}); but form.serialize () is not picking all the form controls in the command form. This list appears to be for each item Hidden form Select the field.
The code in this view is inside a loop, which displays all the items:
**** This is the only control being taken Is: **** ** @HTML.Hinded (IndexITAMID, JetOostring ()) **** & div; div class = "datetext" style = "float: right; margin-down: 5px;" & gt; @models.news [jm] .data posted .toLongDateString () @if (Model.newsItems [j] .showEdit) {// ********** Editor Editor ********************* *** div & gt; @html.editorfor (model => model.News item [ja]) & lt; / Div & gt; } Else {// show the general demo *** {String editID = "editItem_" + Model News [J] .itemID.ToString (); String removal id = "delete itam_" + model Newsite [J]. ITEMID. Ostring (); & Lt; Div class = "buttonblock" & gt; & Lt; Div style = "float: right" & gt; & Lt; Input id = "@ editID" name = "@ editID" type = "submit" class = "cancel smallsubmittext" title = "edit this item" value = "edit" /> & Lt; / Div & gt; & Lt; Div style = "float: right" & gt; & Lt; Input id = "@ deleteID" name = "@ deleteID" type = "submit" class = "smallsubmittext" title = "delete this item" value = "delete" /> & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "clear" & gt; & Lt; / Div & gt; } It is not taking anything but the series of hidden form fields (indexItemID). Why will not this button take control?
(The way the Edit Button is the control id, it is in the form of "editItem_x" where x is an item ID. Thus the buttons are central to the whole process - in this way I know this Finding the item that the user wants to edit)
Update The answer may be in the jQuery API itself: "Not submitted Since the form is not submit button using a button the button value is serial. "
I do not know what is considered to be the button which was clicked to know my actions, so I'm manually adding buttons to the serialized string and it seems that in this work is unable.
UPDATE 2 I too talk soon - Ajax is not working to update my partial view. This is giving me an exception because one section of my layout page is undefined. I lose - I can not waste it at any time. Any Ajax for this project
You can try:.
form = $ ('# NewsForm *'); // Note '*' Update Did you make the argument $ Post () changed on as well? I think that maybe I have become very simple in my answer. Just the second argument to $ Change
inside using
Comments
Post a Comment