gpt4 book ai didi

javascript - 如何在 asp.net 中通过单击按钮来执行 C# 代码?

转载 作者:行者123 更新时间:2023-12-03 03:56:11 26 4
gpt4 key购买 nike

我需要通过单击按钮来执行 C# 代码的帮助。然而,我确信这有很多问题;任何帮助将非常感激。感谢您花时间查看这篇文章,祝您度过愉快的一天!

            @{
CommentController controller = new CommentController();

UpVotes Upvote = new UpVotes(Misc.GetUser(), c.Postid);

}


@{
if (controller.CheckVote(Upvote))
{
<button type="button" onclick="@{

c.Upvotes += 1;

controller.PersonUpVote(Upvote);
}
}">
Like
</button>
}

else
{


<button type="button" onclick="@{

controller.PersonDownVote(Upvote);
c.Upvotes -= 1;
}

}">
Unlike
</button>

}
}

最佳答案

回顾一下你迄今为止所做的一切,直到你走上了错误的道路。

在您的 View 中,您需要通过 JavaScript 附加到按钮单击,然后向 Controller 发出 Ajax 回调。

参见此处http://www.makeitspendit.com/calling-asp-mvc-controllers-from-jquery-ajax/

关于javascript - 如何在 asp.net 中通过单击按钮来执行 C# 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44936937/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com