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

前端 未结 2 1325
无人及你
无人及你 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:01

    One of the common reason causing this error is using the some kind of reserve words such as "Action, Comment, Filter, etc.". So, changing the Action name "Filter" with another name i.e. "ApplyFilter" will probably solve the problem. Hope this helps...

    0 讨论(0)
  • 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<String>() 
                    .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)

    0 讨论(0)
提交回复
热议问题