C# razor/ASP.NET网页多个按钮
我在同一个页面(Razor/ASP.NET网页)中有两个按钮,如何检查单击的按钮 到目前为止,我已经:C# razor/ASP.NET网页多个按钮,c#,asp.net,razor,C#,Asp.net,Razor,我在同一个页面(Razor/ASP.NET网页)中有两个按钮,如何检查单击的按钮 到目前为止,我已经: if (IsPost) { //code block here } 从清除按钮中删除“提交”类,并将其类型更改为“按钮” . 这将阻止它发布表单。请尝试以下操作: if (IsPostBack) { if(! string.IsNullOrEmpty(Request.Form["Button2"])) Response.Write("{Button
if (IsPost)
{
//code block here
}
从清除按钮中删除“提交”类,并将其类型更改为“按钮”
. 这将阻止它发布表单。请尝试以下操作:
if (IsPostBack)
{
if(! string.IsNullOrEmpty(Request.Form["Button2"]))
Response.Write("{Button2 was clicked");
}
不确定它是否有用,但我使用了“formaction”属性,该属性使用完整的URL来定义在后端调用哪个方法。也许可以基于此为您的非MVC需求提供一些解决方案。谢谢各位,我接受了ConvertToInt32答案,它解决了我的问题错误2“IsPostBack”名称在当前上下文中不存在,我使用的是razor/ASP.NET网页这在ASP.NET Web表单中有效,而不是wep页面
if(IsPost){
if (Request.Form["clear"] != null)
{
//when clear clicked
}
else if (Request.Form["update"] != null)
{
//when update clicked
}
}
if (IsPostBack)
{
if(! string.IsNullOrEmpty(Request.Form["Button2"]))
Response.Write("{Button2 was clicked");
}