c# - Include search string in URL for Razor MVC view -


i'm attempting add search string (e.g. http://stackoverflow.com?this=that) view returned controller. being used js on page can't change, other ways transfer data aren't option.

currently i'm returning view("page", viewmodel); controller, doesn't seem allow pass via url.

i tried using return redirecttoaction("a", "b", new { = }); can't work out how return view correctly both view model , url string.

how go adding on ?a=b style string returned view?

a view doesn't have query string arguments, request does. if controller action:

public actionresult someaction() {     return view(); } 

then whatever request made someaction needs have query string parameter:

http://hostname/widgets/someaction?something=somevalue 

the action may accept parameter:

public actionresult someaction(string something) 

but doesn't need if server-side code isn't going value.


if request someaction can't modified, you'll need break apart 2 actions. first 1 redirects second:

public actionresult someaction() {     return redirecttoaction("widgets", "someotheraction", new { = somevalue }); }  public actionresult someotheraction() {     return view(); } 

in scenario first action's responsibility forward user second action particular route parameter. necessary because query string needs in request browser, not in response server. first action's response direct browser make new request query string.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -