如何使MVC3支持AJAX刷新? [英] how to make MVC3 support AJAX refresh?

查看:116
本文介绍了如何使MVC3支持AJAX刷新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是MVC3的新手.
在我的第一个项目中,我遇到了一个有线问题,即在视图中使用Ajax.BeginForm时,控制器无法获取Ajax请求,即.. Request.IsAjaxRequest()返回false.我几乎吓坏了.
有人可以帮我吗?
1.我的查看页面:



I''m a newbie on MVC3.
In my first project, i encounted a wired problem that when i''m using Ajax.BeginForm in view, the controller cannot get the Ajax request, that.., the Request.IsAjaxRequest() returns false. I almostly freak out with it.
Could someone help me?
1. My View page:

@{
    ViewBag.Title = "Home Page";
    Layout = "~/views/shared/_Layout.cshtml";
}

<div id="tardiv"></div>    

@using (Ajax.BeginForm("PartialView1", new AjaxOptions(){ UpdateTargetId = "tardiv"}))
{
    <input type="submit" value="Refresh" />
}
<br />


2. _layout.cshtml:


2. The _layout.cshtml:

<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/microsoftajax.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
</head>

<body>
    @RenderBody()
</body>
</html>


3.控制器:


3. The controller:

public string PartialView1()
       {
           var bajax = Request.IsAjaxRequest(); // always false!!!
           return "wxyz";
       }

推荐答案

尝试一下
http://stackoverflow.com/questions/5866326/updatepanel-in-razor-mvc-3 [^ ]
Try this
http://stackoverflow.com/questions/5866326/updatepanel-in-razor-mvc-3[^]


非常感谢,先生.
我发现原因是在web.config中将"UnobtrusiveJavaScriptEnabled"设置为"true".
设置为false没关系.
我不太了解mvc3,需要更多的精力.
Thank you very much, sir.
I found the reason is "UnobtrusiveJavaScriptEnabled" is set to "true" in web.config.
It ''s ok when set to false.
I don''t understand mvc3 well and need more effort.


这篇关于如何使MVC3支持AJAX刷新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆