Asp.net mvc 3 mvc3 jquery mobile如何使用Html.BeginForm
我已经用MVC3写了一个完整的站点。我正在尝试使用Jquery mobile构建移动版。我没有更改控制器代码,只是添加了一个检查,检查它是否应该返回移动页面。我的移动登录页面的文档头中有以下内容:Asp.net mvc 3 mvc3 jquery mobile如何使用Html.BeginForm,asp.net-mvc-3,jquery-mobile,Asp.net Mvc 3,Jquery Mobile,我已经用MVC3写了一个完整的站点。我正在尝试使用Jquery mobile构建移动版。我没有更改控制器代码,只是添加了一个检查,检查它是否应该返回移动页面。我的移动登录页面的文档头中有以下内容: <head> <title>Mobile Logon</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="styl
<head>
<title>Mobile Logon</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0-alpha.1/jquery.mobile-1.2.0-alpha.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
$(document).bind("mobileinit", function(){
$.extend( $.mobile , {
ajaxEnabled: false
});
});
<script src="http://code.jquery.com/mobile/1.2.0-alpha.1/jquery.mobile-1.2.0-alpha.1.min.js"></script>
</head>
而第二个则给出一个带有
action="Register"
action="Account/Register"
另一个区别是表单标记中的数据ajax=false
问题:
我能用Jquery Mobile使用@Html.BeginForm吗?如果没有,如何重定向到其他控制器
为什么我在head部分的代码没有关闭Jquery Mobile的默认ajax行为?我尝试在没有数据ajax=false的情况下使用上面的表单标记,结果得到了与@Html.BeginForm给我的相同的空白、白色屏幕
编辑:这是我的登录控制器代码帐户控制器
public ActionResult LogOn()
{
//return View();
return SelectView("Logon", null);
}
private ActionResult SelectView(string viewName, object model, string outputType = "html")
{
if (outputType.ToLower() == "json")
{
return Json(model, JsonRequestBehavior.AllowGet);
}
else
{
#if MOBILE
return View(viewName + ".Mobile", model);
#else
if (Request.Browser.IsMobileDevice)
{
return View(viewName + ".Mobile", model);
}
else
{
return View(viewName, model);
}
#endif
}
}
public ActionResult Register(string returnUrl = "")
{
//if no return url supplied, use referrer url.
//Protect against endless loop by checking for empty referrer.
if (String.IsNullOrEmpty(returnUrl) && Request.UrlReferrer != null && Request.UrlReferrer.ToString().Length > 0)
{
return RedirectToAction("Register", new { returnUrl = Request.UrlReferrer.ToString() });
}
return View();
}
这是我的注册控制器代码:帐户控制器
public ActionResult LogOn()
{
//return View();
return SelectView("Logon", null);
}
private ActionResult SelectView(string viewName, object model, string outputType = "html")
{
if (outputType.ToLower() == "json")
{
return Json(model, JsonRequestBehavior.AllowGet);
}
else
{
#if MOBILE
return View(viewName + ".Mobile", model);
#else
if (Request.Browser.IsMobileDevice)
{
return View(viewName + ".Mobile", model);
}
else
{
return View(viewName, model);
}
#endif
}
}
public ActionResult Register(string returnUrl = "")
{
//if no return url supplied, use referrer url.
//Protect against endless loop by checking for empty referrer.
if (String.IsNullOrEmpty(returnUrl) && Request.UrlReferrer != null && Request.UrlReferrer.ToString().Length > 0)
{
return RedirectToAction("Register", new { returnUrl = Request.UrlReferrer.ToString() });
}
return View();
}
两个示例中生成的URL是什么?第一个似乎进入了www.yoursite.com/Register,而第二个不起作用的则进入了www.yoursite.com/Account/Register。。你想要哪一个?我想去/开户/登记。单击任一按钮后,url显示www.mysite.com/Account/Register。一个不工作的给了我一个白色的,空白的屏幕,但另一个工作很好,我怀疑这里还有更多的事情。您能给我们看一下您的控制器代码吗?我为登录获取和注册获取操作添加了控制器代码。这是非常基本的…我注意到您在脚本之后加入了jquery.mobile。。你能把它移到脚本上方然后再试一次吗?此外,$.mobile的扩展名似乎不在任何脚本标记中。。