I’m trying to return route values in my view using a function:
VIEW:
@functions {
public Dictionary<string, object> GetFilters()
{
var filters = new Dictionary<string, object>();
var f_phrase = this.Request["f_phrase"] ?? string.Empty;
var f_site = this.Request["f_site"] ?? string.Empty;
var f_device = this.Request["f_device"] ?? string.Empty;
var f_startdate = this.Request["f_startdate"] ?? string.Empty;
var f_enddate = this.Request["f_enddate"] ?? string.Empty;
var f_package = this.Request["f_package"] ?? string.Empty;
filters.Add("f_phrase", f_phrase);
filters.Add("f_site", f_site);
filters.Add("f_device", f_device);
filters.Add("f_startdate", f_startdate);
filters.Add("f_enddate", f_enddate);
filters.Add("f_package", f_package);
return filters;
}
}
Then on my link I want to be able to do this:
@Html.ActionLink("Export file", "Export", "Log", new { @GetFilters() }, new { @class="iconDocumentText"})
but doesn’t work.
From the MSDN on the
routeValuesparameter:So you need to construct an object and return that instead of returning a dictionary (not sure, but maybe you can achieve this with
dynamic/ExpandoObjector just create a custom type with properties named according to your route values).Example:
Markup: