The parameter conversion from type 'System.String' to type 'T' failed because no type converter can convert between these types

前端 未结 2 1341
无人及你
无人及你 2020-12-21 09:24

NOTE: All of the code here is paraphrased as an example, as I can\'t show real code.

I have a view model class that looks something like

<         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-21 10:02

    A RedirectToAction is simply a HTTP 302 redirect. Are you sure you need the browser to re-request a new page?

    For instance do you want to avoid a page reload from triggerring a "resubmit post data" dialog? (see POST-REDIRECT-GET pattern)

    Why not just use:

    public ActionResult Filter(FormCollection formParams) 
    {
       return Search(new SearchViewModel{
         Term = formParams["Term"], 
         Filters =  
           formParams.Keys 
                    .Cast() 
                    .Where(k => k.Contains("filter")) 
                    .Select(k => Filter.Build(k, formParams[k])) 
                    .ToList()                         
        });                                         
    } 
    

    Alternatively you could use TempData to store the state between requests, or possibly client side cookies if suitable.

    If you want the Search results page to be bookmarkable in a users browser you'll need to represent the search parameter's state in the URL using REST or some form of serilaised string (eg. JSON)

提交回复
热议问题