W3C validation for server-side form tag
Asked Answered
I

3

8

I've checked my website html validation in w3.org and got this error

Bad value for attribute action on element form: Must be non-empty.

but my form is asp.net server-side form and I can't set action atribute.

How can I solve this error?

Inclinatory answered 13/4, 2012 at 0:8 Comment(0)
M
11

This is an old post, but for future reference in ASP.NET one can do the following to avoid blank action attributes:

<form action="#" runat="server">

This will validate with W3C and does not require you to do any special coding to detect the page url you are currently on.

Mccay answered 25/4, 2012 at 11:5 Comment(4)
Actually, this is problematic. If you attempt to do a post with the action="#" solution, you'll get an HTTP verb server-side error.Lovegrass
@Lovegrass I've been using this solution for a while now in ASP.NET without your reported problem, any idea of why this happens?Mccay
May be a problem with the version or setting of IIS (I suspect it's a security setting to prevent certain types of script injection)? Is your page doing any postbacks?Lovegrass
@Lovegrass Yes, postbacks are also ok. Perhaps you should list your setup and I can try and recreate your bug?Mccay
A
7
form1.Action = Request.Url.AbsoluteUri;

this is working for me

Administrator answered 15/10, 2012 at 11:43 Comment(0)
C
2

Omit the attribute action. According to HTML5 drafts, it is not required, but if present, its value must be non-empty. Reference: WHATWG HTML5 draft, description of action attribute.

Clubbable answered 13/4, 2012 at 5:6 Comment(2)
In ASP.NET you cannot omit the action attribute, if you code <form runat="server"> it will render as <form action=""> ; its just the way it works. See my response for a better solution.Mccay
Every time I learn something new about ASP.NET I hate it some more.Coracle

© 2022 - 2024 — McMap. All rights reserved.