My web-api controller has a GET method to search for domain availability with the route:
api/domain/query/
I would like to construct a form that GETs to this path (by the way do you think POST is better in this case?)
This is crap/bad/wrong, but it is where I am so far (PS I want the form to have an ID).
Model.Name is the domain name:
@using (Html.BeginForm("query", "api/domain", FormMethod.Get, new { id = "domain-query" }))
{
@Html.ValidationSummary(true)
<div class="editor-field">
@Html.EditorFor(Model => Model.Name)
@Html.ValidationMessageFor(Model => Model.Name)
</div>
<p>
<input type="submit" value="Search" />
</p>
}
This will result in: api/domain/query?Name=test instead of api/domain/query/test
Appreciate your help and I know its a noob question sorry.
Couple of things here:
1) Do not use GET for your form. MVC forms in this manner should be POSTed except in special cases.
2) Your
BeginFormis wrong. You want the action name and controller name with this overload, but most times you shouldn’t have to worry about it. Again, in most cases you will wantlike so.
You also don’t want to put a “path” for a controller when prompted for a controller. If your controller name is
AppControllerthe string forcontrollershould simply beApp.Looking at this example, I expect you’re going to have a bunch of other problems. Until you wrap your brain around how it’s supposed to work, you’re going to have quite a few issues to work out. I strongly suggest walking through the “Nerd Dinner” tutorial for understanding how to write MVC code.