I have the following code code
public ActionResult Tabs(SearchViewModel svm) { if (Request.IsAjaxRequest()) { svm.Summary = _entitySearchService.GetSearchDataSummary(svm.Search); return PartialView(svm); } else { return RedirectToAction("QuickSearch", "Search" , new RouteValueDictionary { { "search", svm.Search } }); } }
if the user submits a search that ends with a space, for example. "something", it works fine if it is an ajax request, but if it is not an ajax request, the request is redirected to another action method, after which something goes wrong and 404 is returned.
I could do trim() in an else clause, for example.
new RouteValueDictionary { { "search", svm.Search.Trim() } }
but there are several places that this happens. Ideally, I could do it all in one place.
Would it be considered too hacky if I put it in the Controller Initialize method?
protected override void Initialize(RequestContext requestContext) {
Or is there another better way?
source share