tags:

views:

1707

answers:

5

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.

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.

Thanks!

A: 

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?

jdecuyper
A: 

This is quick response!!

I am trying to run this "Simple Tabs" on this page: http://stilbuero.de/jquery/tabs/

I think it is the same with this one: 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.

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.

I can understand some of the MVC+Jquery+json articles, but I don't understand why the hide/show doesn't work.

Thanks!

+3  A: 

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}.

Thanks!

A: 

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

Your post bumped this; you might want to see my post, which is easier to use...
Marc Gravell
+1  A: 

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:

    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:

    <%=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.

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