如何在 ASP.NET MVC 中使用带有 PostBack 的服务器控件?
一旦我单击该按钮,它就会抛出“视图状态 MAC 验证失败”异常。 我知道 MVC 不支持 PostBack,但是有什么办法可以解决这个问题吗?
或者我们需要在MVC中使用HtmlHelper?
下面是我在视图中的代码:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<form id="form1" runat="server">
<h2>Hello World</h2>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</asp:Content>
Once I click the button, it throws a "Validation of viewstate MAC failed" exception. I know MVC does not support PostBack but is there any way to work around this?
Or we need to use HtmlHelper in MVC?
Below is my code in View:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<form id="form1" runat="server">
<h2>Hello World</h2>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</asp:Content>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要对抗你的框架 - 如果你想使用 ASP.NET MVC,那就继续使用它,但是 使用框架的工具创建控件。
如果您想要或需要使用回发控件,那么您确实应该坚持使用常规的旧 ASP.NET。
Don't fight your framework - if you want to use ASP.NET MVC, then go ahead and use it but create controls using the tools of the framework.
If you want or need to use postback controls then you really ought to stick with regular old ASP.NET.
http://somewebguy.wordpress.com/2009 /07/27/webcontrols-in-mvc-part-1/
http://somewebguy.wordpress.com/2009 /08/07/webcontrols-in-mvc-part-2/
http://somewebguy.wordpress.com /2009/08/12/using-webcontrols-in-mvc-part-3/
http://somewebguy.wordpress.com/2009/07/27/webcontrols-in-mvc-part-1/
http://somewebguy.wordpress.com/2009/08/07/webcontrols-in-mvc-part-2/
http://somewebguy.wordpress.com/2009/08/12/using-webcontrols-in-mvc-part-3/