How do I correct my routing to fix an issue with ajax .load()
I modified my route to my spacecontroller so that it looks like this
routes.MapRoute(
name: "SpaceCleanRoute",
url: "Space/{id}",
defaults: new { controller = "Space", action = "Index" }
);
so that I have a cleaner route and when a user wants to see a space the URL will look like this
www.mysite/space/12345
the problem I'm having now is when my JS file calls a .load() like this, , where spaceoverview is my action
$("#partialPageContainer").load('/Space/SpaceOverview', function (response, status, xhr) {
alert("Load was performed.");
});
I get an error saying
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(Int32)' in 'YogaBandy2017.Controllers.SpaceController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters
So I have to put an id after the url like this, which is not what I want, or doesn't seem right to me
How can I fix this or is this just how the routing works? I'm kinda new to mvc routing with ASP.Net
$("#partialPageContainer").load('/Space/SpaceOverview/1', function (response, status, xhr) {
alert("Load was performed.");
});
UPDATED - I guess for now I'll just use '/space/actionname/1' to connect to each action, until I can find a better solution.