1

I am using hash to open mybootstrap modal. When I type Home/Index#mymodal in the URL manually , it works. The modal is displayed automatically. The problem is when I want to submit the form. Below is my code. I try to direct the form to Home/Index#mymmodal. But the URL shows Home/Index%23mymmodal?inputName=john. When I try to change the URL manually Home/Index?inputName=john#mymmodal, it works. So I try to append the #mymmodal at the end of the current the URL. I used this but it does not work.

$('.ajaxLink').click(function (e) {
  location.hash = this.id; // get the clicked link id
  e.preventDefault(); // cancel navigation

  // get content with Ajax...
});

This is my code:

<form method="get" action="@Url.Action("Index#mymodal", "Home")">
    <input type="text" name="inputName" Class="form-control">
</form>

<Button type="submit" value="search">Search</Button>
hud.
  • 160
  • 1
  • 14

1 Answers1

1

The first parameter in the UrlHelper maps to the action for which you're generating a link. You'll never have a method on your controller named Foo#Something - that's not a valid identifier in C#, VB.NET, etc.

If you want a hash appended to the URL, add it after the helper:

<form method="get" action="@Url.Action("Index", "Home")#mymodal">
    <input type="text" name="inputName" Class="form-control">
</form>

The hash isn't included in the HTTP request to the server, though, so I'm not sure what you're trying to accomplish here.

Tieson T.
  • 20,774
  • 6
  • 77
  • 92