ASP MVC3问题与URL加入JQueryMobile后 [英] ASP MVC3 Problems with URL after adding JQueryMobile

查看:221
本文介绍了ASP MVC3问题与URL加入JQueryMobile后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都具有MVC3和jQuery 1.7.1和jQuery Mobile的1.1.0烦恼吗?每当我提出一个标准的MVC形成我的网址,从云:

Anyone else having trouble with MVC3, JQuery 1.7.1 and JQuery Mobile 1.1.0? Whenever I submit a standard MVC form my URL goes from:

本地主机/网站/控制器/动作

本地主机/网站/控制器/动作#/控制器/动作

我在简化现有的网站,是相当混乱使感到控制器通过控制器工作,清理和删除那些不需要它的jquery表单处理,并只用剃刀的中间。我想知道,如果东西在我的项目是相互矛盾的,但我已经成功地从一个新的项目复制它:

I'm in the middle of simplifying an existing site that is quite messy so am working through controller by controller cleaning up and removing jquery form handling where it isn't required and just using Razor. I wondered if something in my project was conflicting but i've managed to replicate it from a new project:

打开VS2010,新的空MVC3项目 - 即一切下面没有提到是默认MVC项目

Open VS2010, New Empty MVC3 Project - i.e. everything not mentioned below is the default MVC project

添加的TestController:

Add TestController:

using System.Web.Mvc;
using MvcApplication1.Models;

namespace MvcApplication1.Controllers
{
    public class TestController : Controller
     {
        public ActionResult Testing()
        {
            return View(new TestModel());
        }

        [HttpPost]
        public ActionResult Testing(TestModel testModel)
        {
            if (ModelState.IsValid)
            {
                //Temp for examples sake
                ModelState.AddModelError("EmailAddress", "Account not found.");
            }

            return View();
        } 
    }
}

添加TestModel:

Add TestModel:

using System.ComponentModel.DataAnnotations;

namespace MvcApplication1.Models
{
    public class TestModel
    {
        [Required(ErrorMessage = "Email is required.")]
        [DataType(DataType.EmailAddress)]
        [StringLength(50, ErrorMessage = "Email too long.")]
        public string EmailAddress { get; set; }
    }
}

添加文件夹视图与试验测试观点:

Add view Folder Test with view Testing:

@model MvcApplication1.Models.TestModel

@using (Html.BeginForm("Testing", "Test", FormMethod.Post))
{ 
    <div id="divForgotPassword">
        <fieldset data-role="fieldcontain">
            <legend>Forgot Password</legend>
            <div id="editor-label">
                <label for="txtLogonID">
                    Email Address:</label></div>
            <div id="editor-field">
                @Html.TextBoxFor(m => m.EmailAddress, new { type = "email" })
                <br />
                @Html.ValidationMessageFor(m => m.EmailAddress)</div>
            <input type="submit" value="Reset Password" data-role="button" data-inline="true" />
        </fieldset>
    </div>
}

运行和访问的http://本地主机:65298 /测试/测试
打重置密码,验证工作,URL不会改变。

Run and visit http://localhost:65298/Test/Testing Hit Reset Password, validator works, URL doesn't change

添加jquery.mobile-1.1.0.js和jQuery-1.7.1.min.js到脚本文件夹

Add jquery.mobile-1.1.0.js and jquery-1.7.1.min.js to scripts folder

要_Layout.cshtml补充:
与变革的jQuery 1.5.1 1.7.1

To _Layout.cshtml add: And Change jquery 1.5.1 to 1.7.1

运行,并再次访问我们的网页
打重置密码,验证工作,但现在你必须:
的http://本地主机:65298 /测试/测试#/测试/测试

Run and visit our page again Hit Reset Password, validator works but now you have: http://localhost:65298/Test/Testing#/Test/Testing

我一定是做错了什么?与此主要问题是与URL其他JavaScript我不喜欢跑。我也担心它会用别的东西interefere,再加上它看起来丑陋,有错...

I must be doing something wrong?? The main problem with this is that with that URL other javascript I have doesn't like to run. I also worry it will interefere with something else, plus it looks ugly and has to be wrong...

提前很多感谢!

推荐答案

这是jQuery Mobile的默认行为。对于所有的链接,而不是正常的方式加载页面,它发出了一个Ajax请求并加载网页,然后更新(只是附加)的URL。

That is the default behaviour of jQuery mobile. For all links, instead of loading a page in normal way, It sends an ajax request and load the page and then update(just append) the url.

如果要禁用此行为,你可以把的rel =外部中的链接和链接
将加载没有Ajax,然后你的URL将照常进行。

If you want to disable this behaviour, you can put rel=external in the link and the link will load without ajax and your url will then be usual.

<a href="User/somepage" rel="external" />I wont be using ajax for navigation</a>

http://jquerymobile.com/demos/ 1.0a4.1 /#文档/网页/文档,navmodel.html

这篇关于ASP MVC3问题与URL加入JQueryMobile后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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