简体   繁体   English

在ASP.NET MVC框架中使用JQuery

[英]Using JQuery with ASP.NET MVC Framework

I have searched the forum, and google for this topic. 我搜索了论坛,并谷歌搜索这个主题。 Most of the articles are talking about using JSON to call the controller/action on the server and do ajax effect on the result. 大多数文章都在谈论使用JSON来调用服务器上的控制器/操作,并对结果执行ajax效果。

I am trying to use some very basic JQuery features, like the JQuery UI/Tabs, and JQuery UI/Block for a dialog window. 我试图使用一些非常基本的JQuery功能,如JQuery UI / Tabs,以及JQuery UI / Block用于对话框窗口。 I cannot get these simple samples to work in my MVC project. 我不能让这些简单的样本在我的MVC项目中工作。 Any ideas how I should modify these samples? 有什么想法我应该如何修改这些样品? I only need these basic feature now and I can go from here. 我现在只需要这些基本功能,我可以从这里开始。

Thanks! 谢谢!

Actually I just got it working. 其实我刚刚开始工作了。 The problem is that I need to modify the path to an absolute path to the view page because the relative path doesn't work with the MVC routes {controller}/{action}/{id}. 问题是我需要修改到视图页面的绝对路径的路径,因为相对路径不适用于MVC路由{controller} / {action} / {id}。

Thanks! 谢谢!

For info, re the relative path issue - I discussed this here (the same concept applies to any page, not just master pages). 有关信息,请查看相对路径问题 - 我在此讨论 (相同的概念适用于任何页面,而不仅仅是母版页)。 The approach I used is like so: 我使用的方法是这样的:

1: declare an extension method for adding scripts: 1:声明添加脚本的扩展方法:

    public static string Script(this HtmlHelper html, string path)
    {
        var filePath = VirtualPathUtility.ToAbsolute(path);
        return "<script type=\"text/javascript\" src=\"" + filePath + "\"></script>";
    }

2: when needed (for example in the <head>...</head> ) use this method: 2:需要时(例如在<head>...</head> )使用此方法:

    <%=Html.Script("~/Scripts/jquery-1.2.6.js")%>

The advantage of this is that it will work even if the web app is hosted in a virtual directory (ie you can't use "/Scripts" because you aren't necessarily at the site root) - yet it is a lot clearer (and less messy) than the full script with munged src, ie 这样做的好处是,即使Web应用程序托管在虚拟目录中也是可行的(即您不能使用“/ Scripts”,因为您不一定是站点的根目录) - 但它更清晰(而不是使用munged src的完整脚本,即

    <script ... src="<%=Url.Foo(...)%>"></script>

I just implemented the jquery autocomplete textbox in one of my asp.net project. 我刚刚在我的一个asp.net项目中实现了jquery自动完成文本框。 I only had to import the js file and drop some code into my aspx page. 我只需导入js文件并将一些代码放入我的aspx页面。 Could you be more detailled about what sample you are trying to run? 您是否可以更详细地了解您试图运行的样品?

This is quick response!! 这是快速反应!!

I am trying to run this "Simple Tabs" on this page: http://stilbuero.de/jquery/tabs/ 我试图在此页面上运行此“简单选项卡”: http//stilbuero.de/jquery/tabs/

I think it is the same with this one: http://docs.jquery.com/UI/Tabs 我认为这与此相同: http//docs.jquery.com/UI/Tabs

I just copied and pasted the whole thing into my MVC view page, with corrected path to the jquery.js and .css files, but the content in the tabs all show up together (two of them are supposed to be hidden). 我只是将整个事物复制并粘贴到我的MVC视图页面中,并修正了jquery.js和.css文件的路径,但是选项卡中的内容都显示在一起(其中两个应该被隐藏)。 My understanding is that this simple jquery plugin just show and hide content. 我的理解是这个简单的jquery插件只显示和隐藏内容。

I had the exact same problem with the jquery thickbox plugin, that the item marked as "hidden" (the dialog box) will always show up in my MVC view page. 我在jquery thickbox插件中遇到了完全相同的问题,标记为“隐藏”(对话框)的项目将始终显示在我的MVC视图页面中。

I can understand some of the MVC+Jquery+json articles, but I don't understand why the hide/show doesn't work. 我可以理解一些MVC + Jquery + json文章,但我不明白为什么hide / show不起作用。

Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM