Hi,
I am stuck in one simple issue. I need a redirection from existing URL to another URL taking some parameters from current DOM. Basically, I need to call another action method of a controller along with passing some parameters.
What I have tried:
Following in my anchor element:
<a id="Link1" onclick="callActionMethod(this.id);">Link1</a>
Following is the Javascript Code:
function callActionMethod(linkId) {
window.location.href = Url.Action("MyActionMethod", "MyController") + '?Param1=' + param1Value + '&Param2=' + param2Value + '&Param3=' + param3VAlue + '&Param4=' + param4VAlue;
}
Action Method:
public ActionResult MyActionMethod (DateTime Param1, DateTime Param2, string Param3, string Param4)
{
}
However, I am getting the following error while clicking the link1:
The parameters dictionary contains a null entry for parameter 'Param1' of non-nullable type 'System.DateTime' for method 'System.Web.Mvc.ActionResult MyActionMethod(System.DateTime, System.DateTime, System.String, System.String, System.String, System.String, Boolean, Boolean)' in '~.Controllers.Common.MyController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
I guess it is some routing error. Following is the route.config entry:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = defaultController, action = defaultAction, id = UrlParameter.Optional }
);
I dont think I can change the route.config file and make one more entry to accommodate these many parameters. How else can I make this work? Any other approach for redirecting? Any help will be appreciated.