在ASP.NET MVC框架中使用JQuery

时间:2022-12-01 08:16:16

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. I cannot get these simple samples to work in my MVC project. Any ideas how I should modify these samples? I only need these basic feature now and I can go from here.

我试图使用一些非常基本的JQuery功能,如JQuery UI / Tabs,以及JQuery UI / Block用于对话框窗口。我不能让这些简单的样本在我的MVC项目中工作。有什么想法我应该如何修改这些样品?我现在只需要这些基本功能,我可以从这里开始。

Thanks!

5 个解决方案

#1


3  

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!

#2


1  

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:需要时(例如在 ... 中)使用此方法:

    <%=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 (i.e. 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, i.e.

这样做的好处是,即使Web应用程序托管在虚拟目录中也是可行的(即,您不能使用“/ Scripts”,因为您不一定在站点根目录) - 但它更清晰(并且比使用munged src的完整脚本更少杂乱,即

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

#3


0  

I just implemented the jquery autocomplete textbox in one of my asp.net project. I only had to import the js file and drop some code into my aspx page. Could you be more detailled about what sample you are trying to run?

我刚刚在我的一个asp.net项目中实现了jquery自动完成文本框。我只需导入js文件并将一些代码放入我的aspx页面。您是否可以更详细地了解您试图运行的样品?

#4


0  

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). My understanding is that this simple jquery plugin just show and hide content.

我只是将整个事物复制并粘贴到我的MVC视图页面中,并修正了jquery.js和.css文件的路径,但是选项卡中的内容都显示在一起(其中两个应该被隐藏)。我的理解是这个简单的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!

#5


0  

I just made a walkthrough on how to do this:

我刚刚介绍了如何执行此操作:

http://blogs.msdn.com/joecar/archive/2009/01/08/autocomplete-with-asp-net-mvc-and-jquery.aspx

#1


3  

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!

#2


1  

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:需要时(例如在 ... 中)使用此方法:

    <%=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 (i.e. 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, i.e.

这样做的好处是,即使Web应用程序托管在虚拟目录中也是可行的(即,您不能使用“/ Scripts”,因为您不一定在站点根目录) - 但它更清晰(并且比使用munged src的完整脚本更少杂乱,即

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

#3


0  

I just implemented the jquery autocomplete textbox in one of my asp.net project. I only had to import the js file and drop some code into my aspx page. Could you be more detailled about what sample you are trying to run?

我刚刚在我的一个asp.net项目中实现了jquery自动完成文本框。我只需导入js文件并将一些代码放入我的aspx页面。您是否可以更详细地了解您试图运行的样品?

#4


0  

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). My understanding is that this simple jquery plugin just show and hide content.

我只是将整个事物复制并粘贴到我的MVC视图页面中,并修正了jquery.js和.css文件的路径,但是选项卡中的内容都显示在一起(其中两个应该被隐藏)。我的理解是这个简单的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!

#5


0  

I just made a walkthrough on how to do this:

我刚刚介绍了如何执行此操作:

http://blogs.msdn.com/joecar/archive/2009/01/08/autocomplete-with-asp-net-mvc-and-jquery.aspx