ASP.NET MVC: Inputting Forms into Beautiful URLs

I have a url:

Forwarding / Search / {SearchType} / {searchValue}

and controller action:

// ShipmentSearchType is an enum ... PartNumber, CustomerOrder, etc...
ActionResult Search(ShipmentSearchType searchType, string searchValue)

So this means that I can print beautiful URLs, for example:

Forwarding / Search / PartNumber / Widget-01

And get a list of all shipments with this number.

Now I'm working on the application and got to the point where I create a search form that asks for the part number, and it sends it back to Search. So basically I want:

Forwarding / Search / PartNumber / {user input-from-text field}

Unfortunately, I cannot get the form for the above URL - it needs to be generated on the server side. So instead, I will have a form message back to "Shipping / Search / PartNumber" with {user-input} as the value of the submit request.

, :

[AcceptVerbs(HttpVerbs.Post)]
ActionResult Search(ShipmentSearchType searchType, string searchValue, bool? post)
{
    return RedirectToAction("Search", new { searchType = searchType, searchValue = searchValue});
}

2 :

1) , post Search javascript ?

2) Bool? post , . . ?

!

:

" , , ( , javascript)". " , javascript?"

. , , url/Shipment/Search/PartNumber/{value-from-textbox} get. , javascript ( URL-), . , javascript .

+3
1

, javascript, FormCollections [post] Search, :

[AcceptVerbs(HttpVerbs.Post)]
ActionResult Search(FormCollection form)
{    return RedirectToAction("Search", new { searchType = form["searchType"], searchValue = form["searchValue"]}); }

, , Post-Redirect-Get, - asp.net mvc.

+6

Source: https://habr.com/ru/post/1707196/


All Articles