4

How do I make sure .NET does not remove the NAME attribute from my HTML forms. I require this in order to use AngularJS. Please let me know.

in visualstudio my form looks like this:

<form id="scheduleFrm" name="scheduleFrm" runat="server">

but it ends up looking like this in my browser's source:

<form id="scheduleFrm" method="POST"> without the name attribute

AngularJS needs the name attribute but name is available for my form

user3214892
  • 147
  • 1
  • 10
  • 2
    are you using mvc? put your html code for your form, please. – Alexandre TRINDADE Apr 24 '14 at 14:04
  • my form tag looks like this:
    but it removes the name="scheduleFrm" why I look at the source in my browser
    – user3214892 Apr 24 '14 at 14:13
  • @AlexandreTRINDADE: `runat="server"` points towards ASP.Net, unless there's another usage of which I'm not aware. – Flater Apr 24 '14 at 14:21
  • I am wondering why it wont maintain the name attribute and still use runat="server" – user3214892 Apr 24 '14 at 14:22
  • 3
    @user, see [ASP.NET 4 Breaking Changes](http://www.asp.net/whitepapers/aspnet4/breaking-changes): `The HtmlForm control does not render a name attribute`. I don't think there is a workaround. – Frédéric Hamidi Apr 24 '14 at 14:24
  • @Flater yes, I know, but he put html form code after my question. :) – Alexandre TRINDADE Apr 24 '14 at 14:30
  • @user3214892, if you can't change form's name, so you can change your angular code. I think you're using this to do validation? If yes, I put an answer to your question. – Alexandre TRINDADE Apr 24 '14 at 14:31
  • yes I am trying to do some validation but I can make use of the form name. I am new to angularJS and the examples I see on the net make use of the form name. – user3214892 Apr 24 '14 at 14:34
  • Does the following setting in web.config not revert back to .net outputting names.. ``? –  Apr 24 '14 at 14:43
  • 1
    @FrédéricHamidi There is workaround you didn't read the section completely. You can add this setting `` to use Legacy rendering. – vendettamit Jun 08 '18 at 19:42

2 Answers2

2

This is bad but it will get you going again:

<form id="theName" ...>
    <script>document.getElementById("theName").setAttribute("name", "theName");</script>
    <!-- ...formalities -->
</form>
user875234
  • 2,399
  • 7
  • 31
  • 49
  • ... – Taranttini Sep 17 '19 at 19:19
0

There is an workaround. If you do for example:

$scope.scheduleFrm...

to access your form, so you can do:

var formName = $("#scheduleFrm").attr("name");
$scope[formName]...

to do the same.

Alexandre TRINDADE
  • 917
  • 10
  • 21