AngualrJS and C# Code works but another way of doing this

I have a side menu and I click on a link. I want to redirect the user to another page and pass a parameter.

1. In Razor, I do this

 <button ng-click="openForm(row.Id)"  class="btn btn-primary btn-border btn-rounded-20 btn-ef btn-ef-4 btn-ef-4b mb-10">{{row.FormName}}<i class="fa fa-arrow-right"></i></button>

Open in new window


2. In AngularJS controller, I have this
 $scope.openForm = function (formId) {

            //console.log(JSON.stringify(formId))

            //$http({
            //        method: 'POST',
            //        url: '/displayform/index',
            //        data: JSON.stringify(formId),
            //        contentType: "application/json",
            //        dataType: "json"

            //}
               
             

            //    ).then(function () { });

          //  window.open('/displayform/index/' + formId, '_self', false);

            window.location = "/displayform/index/?formId=" + formId; 

        };

Open in new window


3. In C# controller
 // [HttpPost]
        public ActionResult Index(string formId)
        {

            ViewBag.FormId = formId;
            return View();
        }

Open in new window


4. The URL looks like this when the user is redirected
http://localhost:63410/displayform/index/?formId=1

Is there a better way of doing this? I wanted the URL to look like this but couldn't get it working...the passed parameter comes out as null http://localhost:63410/displayform/index/1
LVL 8
CamilliaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Ok several questions

Are you using server side processing to manage your views - any reason why you are not doing this in angular. In other words setup routing in your client and have the angular view link to the razor view through a URL?


Secondly, what format is your view expecting (in terms of the url)
a) parameter passed as ?index=1 (normal query parameters)
b) parameter passed as part of the path /index/1

If (b) how does your server side respond to manually entering the required path into the address bar? I would get this part working first - when the URL is working manually put it back into the Angular code.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CamilliaAuthor Commented:
any reason why you are not doing this in angular
The way I learned it at work is we use MVC routing not angular. That's the reason.

Secondly, what format is your view expecting (in terms of the url)
a) parameter passed as ?index=1 (normal query parameters)
b) parameter passed as part of the path /index/1

I would like it to be /index/1 because I think it's cleaner. But if having it as ?index=1 is ok, then I'll leave it as is.

Code works as I have it now. With Angular and MVC/C#. I just wanted to know if having ?index=1 is OK or should I work on getting the URL like /index/1
Julian HansenCommented:
This is your choice - from a programming perspective it is 6 of one half a dozen of the other. The only reason for doing the index/1 over ?index=1 is pretty urls for the user's benefit.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

CamilliaAuthor Commented:
Thanks, I'll leave it as is. I couldn't read the "1" value in MVC's controller. Would come out as null ... that's why I went with ?index=1
Julian HansenCommented:
It depends how you have set up your view - not the sharpest tool in the shed when it comes to .Net - but if I remember correctly when you setup your routes you specify how the path should be interpreted - but wouldn't be able to tell you how to do that off the top of my head.
CamilliaAuthor Commented:
oh yeah, I think you're right. Totally forgot about that. I think that's it. I'll check it
CamilliaAuthor Commented:
Thanks. I'll look at why the other route doesn't work.
Julian HansenCommented:
You are welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.