10

I am returning some simple HTML markup in a JSON response from an action.

Here is the full response (linebreaks added for readability):

    {
        "Success":true,
        "Content":"\r\n
<div class=\"editor-form\">\r\n

<form action=\"/Blah/Blah/5104?id=9\" method=\"post\">

<input data-val=\"true\" data-val-number=\"The field Id must be a number.\" data-val-required=\"The Id field is required.\" id=\"Id\" name=\"Id\" type=\"hidden\" value=\"5104\" />

<input data-val=\"true\" data-val-number=\"The field Vat Rate must be a number.\" data-val-required=\"The Vat Rate field is required.\" id=\"VatRate\" name=\"VatRate\" type=\"hidden\" value=\"1.2000\" />

<div class=\"display-field\">\r\n\t

<label for=\"Price\">Price (Ex-VAT)</label>\r\n\t

<input class=\"text-box single-line\" data-val=\"true\" data-val-number=\"The field Price must be a number.\" data-val-required=\"The Price field is required.\" id=\"Price\" name=\"Price\" type=\"text\" value=\"92.50\" />\r\n\t

</div>\r\n

</form>
</div>",
"Data":null,
"Errors":null
}

Here is what I do with it after a succesful response:

$("#EditPriceDialog").html(data.Content).dialog(MyProject.UI.DialogOptions({ minWidth:380, minHeight:200, modal:true }))

When the markup renders, the form element is missing. Elements inside the form are still there. This only happens in Chrome. In IE9 and FF 19 the form element is there. What's different in Chrome?

4
  • 1
    I couldn't reproduce it
    – Alexander
    Feb 25, 2013 at 15:29
  • Can you give us something that can reproduce the issue? Feb 25, 2013 at 15:32
  • It is a pretty huge page but I will try...
    – Kev
    Feb 25, 2013 at 15:50
  • happened to me as well, but if I have a input type=text with name and id = Date it doesnt remove the form
    – Omu
    Feb 15, 2014 at 18:17

1 Answer 1

20

Chrome removes form element if it is already surrounded by another form element. Also, ASP .Net renders form tag for all pages it servers, as a result Chrome is stripping off the form tag in data.Content. I don't think IE or firefox behaves this way.

Edit: Hope you will find this useful, How do you overcome the html form nesting limitation?

1
  • I had this issue and it was caused by an unclosed form tag further up the page.
    – Jack
    Aug 7, 2017 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.