0

I am working on Asp.net MVC 4 with Razor. The urls of my projects are like

localhost:port/category1

localhost:port/category2 etc while my controller is home and action is MyCustomAction

I am using Paging on Category1 page with ul li and anchor tag with href="javascript:ShowPage(pagenmbr)"

And Code of ShowPage function is $('#currentpage').val(pagenmbr); $('#myform').submit();

where currentpage is hidden field on my cshtml page

My form is

@using(Html.BeginForm("home","MyCustomAction",FormMethod.Post,new { @id="myform"})

and as i pressed any link for any page functionality is working properly

but in that case my url becomes

localhost:port/category1?controller=home&action=MyCustomeAction

while I don't want this url pattern url should be

localhost:port/category1

Am I doing something in a wrong way, please help me..... please help me out

2
  • "but in that case my url becomes" ... what do you mean , when is this case?? Commented Mar 8, 2014 at 5:19
  • (I just wrote it) not only in this case but in all cases..... when i post my form my url showing action and controller name in query string format Commented Mar 8, 2014 at 5:26

1 Answer 1

2

Obviously, there's something wrong in your routing. Try posting the code from your Route registering class.

Also for the below line:

@using(Html.BeginForm("home","MyCustomAction",FormMethod.Post,new { @id="myform"})

Try switching this to:

<form method="post" id="myform">

Doing this, will force the form to always submit to the current Url.

And you can't use the HtmlHelper to generate this as you need to specify the htmlAttributes which can only be passed after the actionName and the controllerName.

Sign up to request clarification or add additional context in comments.

3 Comments

There's nothing wrong in my routing i had checked it twice thrice, in my routing i just checked first level after domain and checks if category exist and defines controller to home and action to MyCustome Action that's it, and if routing would wrong how the get request is giving desired result as localhost:1111/category1
Well Ganesh is right. You should switch to HTML markup.
Thanks... I used Html Form tag and got the desired result... but MVC form is also renders in Html form then how the result is diffrent.... can anyone explain .....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.