Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've just run into the same problem, but possibly a better solution based on <a href="https://stackoverflow.com/questions/4997269/asp-net-mvc-3-generate-unobtrusive-validation-when-beginform-is-on-the-layout/4997920#4997920">Darin Dimitrov's</a> answer.</p> <p>The trick is to create a page base type, based on the <a href="http://msdn.microsoft.com/en-us/library/gg402107(v=vs.98).aspx" rel="nofollow noreferrer"><code>WebViewPage&lt;T&gt;</code></a> class, the default base class for views and do the <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.formcontext.aspx" rel="nofollow noreferrer"><code>FormContext</code></a> swap there.</p> <pre><code>abstract public class FormFixWebViewPage : FormFixWebViewPage&lt;object&gt; { } abstract public class FormFixWebViewPage&lt;T&gt; : WebViewPage&lt;T&gt; { override public void Write(System.Web.WebPages.HelperResult result) { var originalFormContext = ViewContext.FormContext; ViewContext.FormContext = new FormContext(); base.Write(result); ViewContext.FormContext = originalFormContext; } } </code></pre> <p>And then in the <code>Web.config</code> file under the <code>~/Views/</code> folder, alter the <code>pageBaseType</code> attribute under <code>pages</code> element, which can be found in the <code>system.web.webPages.razor</code> section:</p> <pre><code>&lt;system.web.webPages.razor&gt; &lt;host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt; &lt;pages pageBaseType="&lt;YOUR-NAMESPACE&gt;.FormFixWebViewPage"&gt; &lt;!--pages pageBaseType="System.Web.Mvc.WebViewPage"--&gt; &lt;namespaces&gt; &lt;add namespace="System.Web.Mvc" /&gt; &lt;add namespace="System.Web.Mvc.Ajax" /&gt; &lt;add namespace="System.Web.Mvc.Html" /&gt; &lt;add namespace="System.Web.Helpers" /&gt; &lt;add namespace="System.Web.Routing" /&gt; &lt;/namespaces&gt; &lt;/pages&gt; &lt;/system.web.webPages.razor&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload