从 JQuery 调用控制器操作时出错
我的母版页中有此调用:
$.ajax({
type: "POST",
url: "<%= Url.Action("CreateTermSheet", "Indications") %>",
data: GetJSONForID(),
success: function(data) {
alert('Success!');
}
});
但是当我去加载页面时,它不会呈现,并且出现此编译错误:
CS0103:当前上下文中不存在名称“Url”
有什么问题?我在应用程序的其他地方这样做完全没问题。
I have this call in my master page:
$.ajax({
type: "POST",
url: "<%= Url.Action("CreateTermSheet", "Indications") %>",
data: GetJSONForID(),
success: function(data) {
alert('Success!');
}
});
But when I go to load the page it doesn't render and I get this compilation error:
CS0103: The name 'Url' does not exist in the current context
What's wrong? I do this other places in my app completely fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此错误意味着您的视图未引用 System.Web.Mvc。它应该由 Visual Studio 自动添加。检查
/
中 Views Web.config (Project Directory/Views/Web.config) 中的引用This error means here that your views did not reference
System.Web.Mvc
. It should be automatically added by Visual Studio. Check the reference in your Views Web.config (Project Directory/Views/Web.config) in<system.web>/<pages>
确保您的母版页是 MVC 母版页,即它继承自 System.Web.Mvc.ViewMasterPage 而不是来自 System.Web.UI.MasterPage:
然后您将拥有 Url 属性及其各自的 操作方法。
Make sure that your master page is an MVC master page i.e. it inherits from System.Web.Mvc.ViewMasterPage and not from System.Web.UI.MasterPage:
Then you will have the Url property inside and its respective Action method.