如何在 ASP.NET MVC 中使用带有 PostBack 的服务器控件?

发布于 2024-08-01 16:27:55 字数 526 浏览 8 评论 0原文

一旦我单击该按钮,它就会抛出“视图状态 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野生奥特曼 2024-08-08 16:27:55

不要对抗你的框架 - 如果你想使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文