JsActionScript is Missing in Action???

Nov 26, 2011 at 9:16 AM

I wanted to give this a bit of  a test run, as it looks like could really make doing Ajax calls in MVC a really easy process

but I am not able to Locate the "JsActionScript" or "script.js" file

@Html.JsActionScript()

 <script src="../../Scripts/script.js" type="text/javascript"></script>

Is this file missing from the Release (Change Set 12459 )/NuGet package

 

Thanks .net noobie

Coordinator
Nov 26, 2011 at 10:49 AM
Edited Nov 26, 2011 at 10:56 AM

Good morning and thank you a lot for your post.

About your question:
I think both your problems are due to my lack of documentation process. I'm really sorry and i will fix them as soon possible.


1) script.js (that is missing) is not part of project: it's just a simple js file in which you should place your app code. You can create your own or also use it as inline javascript.
In few word, my script.js file contains just this:

$(document).ready(function () {
    var ret = JsActions.MyTestMethod(1,2);
});


2) You are right. The right method name is JsAction. (i have already updated the doc).
If you can't locate it, you should check for JsAction namespace using on top of your view and try to rebuild the project (Vs2010 intellisense does not show all namespaces and members, if project is not rebuilded).
Do not forget to add route in RouteHandler, or action will miss with a 404 error!

I have provided a complete example with JsAction installed as nuGet package, jQuery 1.7.1 and a simple method marked with attribute.
You can download it in the release section.

Thank you again and if you have any other question drop me a line!

Nov 26, 2011 at 12:59 PM
Edited Nov 26, 2011 at 1:02 PM

I did not have the @using JsAction; at the top of the page
I added it to the /Views/Web.Config instead

Thanks 

Nov 26, 2011 at 1:33 PM

when i click of the home page ina MVC3 website

it goes to this Url: http://localhost:1626/JsAction?action=About&controller=Home 

then I will get this in the browser 

var JsActions = {MyTestMethod:function(a,b,options){var opts = {url:"/Home/MyTestMethod",type: "GET",data:{a:a,b:b}};$.extend(opts,options); return $.ajax(opts);}}

Any Idea what I have done wrong?

Coordinator
Nov 27, 2011 at 8:00 AM
Edited Nov 27, 2011 at 8:05 AM

Good morning again and thank you for your post.

Your issue it's very strange, i have no completely understand your question.
If i understand well, when you run your project it redirects you directly to that url (that is route handler which generates javascript).
That's strange, there must be some mistakes in configuring your project.

Anyway, have you tried to have a look to this reference start project? (http://jsaction.codeplex.com/releases/77545/download/307304)
You can check your project with this one and see difference.

I'm always aviable to help you, let me know if you resolve, HOW did you resolve or if not, drop me another line here.
Have a nice day,

Vincenzo

Nov 27, 2011 at 8:38 AM
Edited Nov 27, 2011 at 8:39 AM

OK... same thing happens with the "JsActionTest" project....

what I did:

downloaded the like, run in VS, I get the message box with the value displayed, as expected... this is all fine, and I have this working the same in my own test project... 

to see what the issue i mentioned is:

in the HomeController.cs add a new view e.g. "About" 

        public ActionResult About()
        {
            return View();
        }

Then Added the the view into the Views Folder ../Views/About.cshtml

then in the ../Views/Home.cshtml

add an @ActionLink("About" "About", "Home");

all stock-standard MVC3 stuff... 


Now... run the project.... you will get the message box to display the JsAction Method value as before/expected...

now the issue I get is when i click the new link to goto the About View/Page

this is when the i get the json returned in the browser for the JsAction var..
e.g

var JsActions = {MyTestMethod:function(a,b,options){var opts = {url:"/Home/MyTestMethod",type: "GET",data:{a:a,b:b}};$.extend(opts,options); return $.ajax(opts);}}

So I assume is a Routing Issue of some kind

Thanks David 

Coordinator
Nov 27, 2011 at 8:48 AM

You are right, i got the same issue.
I'm very sorry. I'm working to fix it as soon possible!!

Nov 27, 2011 at 9:01 AM

No Worries...

no need to say "Sorry" :)

Look forward to playing with it a bit more once the Routing issue is sorted out...

Coordinator
Nov 27, 2011 at 10:15 AM
Edited Nov 27, 2011 at 10:28 AM

Good news for you: the issue should now be resolved.

The default route is too eager and catches everything and maps JsAction handler as a controller.
The mistake can be resolved simply using a route constraint and moving route table creation order.
Using this code, you should resolve

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                    "Default",
                    "{controller}/{action}/{id}",
                    new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                    new { controller = "^((?!JsAction).)*$", action = "^((?!JsAction).)*$" }
                );

            routes.Add("JsActionRoute", JsAction.JsActionRouteHandlerInstance.JsActionRoute); 

Let me know if it works in this way.
Thank you a lot for your support.

EDIT:
I published new Changeset, new release (0.1.1) and nuget package upgraded that will handle this issue in route creation.
This will let you work without any code modification: upgrade release and try the SAME project. It should work.

Nov 27, 2011 at 10:28 AM

Yep updated the NuGet package in VS, now works fine...

Thank you 
David 

Coordinator
Nov 27, 2011 at 10:30 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Nov 27, 2011 at 10:33 AM

Thank you a lot for your test and bug signalation.