<form name="mailform" id="mailform" method="post" action="@(ViewBag.Test)" class="testForm">
What I thing that this will render my action attribute like
action="" (in case of
ViewBag.Test = null) but I am confused with ASP.NET MVC's behaviour.
When ViewBag.Test is not defined than my action attribute is not rendering. For confirm I open the View-source in Chrome and Firefox and none of both have action attribute for my form. I also check it by change the text but action attribute is remain not rendering.
Can someone explain what is it? And the link that I can verify it's the common behaviour of ASP.NET MVC 5
Best How To :
It is the MVC framework (or more specifically the Razor engine) that is choosing to remove it. They are known as 'conditional attirbutes' and appear to have been introduced in MVC 4. See here for more information (search for: Conditional attribute rendering), or read this.
I guess the answer to why it has been implemented is likely just for convenience, so coders don't have to write ugly checks to decide if an attribute should be included or not.
If you want to force the empty attribute, then you can just handle null values. For example, like this...
<form name="mailform" id="mailform" method="post" action="@(ViewBag.Test ?? "")" class="jeetForm">