joeaudette / cloudscribe.StarterKits

Deprecated - see below
Apache License 2.0
53 stars 21 forks source link

id in route does not work #26

Closed JanOlsmar closed 7 years ago

JanOlsmar commented 7 years ago

Hi and thanks for this project. I have played with it a lot, learned a lot and like it.

I tested to add a own data layer and a controller and basic crud actions. It seem that if you use id the id part disapare. This happens also for the Home controller in the samples. (I have tested ef sql and ef sql identity server)

So if you in Home/about/456 and

` public IActionResult About(int? id) { ViewData["Message"] = "ID " + id + " Your application description page.";

        return View();
    }

` The id is null.

Jan

joeaudette commented 7 years ago

there are a lot of starterkits, please be specific about which starterkit you are talking about, so I can know what code is involved

joeaudette commented 7 years ago

oh wait I see you mentioned ef sql, will check it

joeaudette commented 7 years ago

ok, figured it out by setting log level to debug to see which route it matched, the problem is this route was catching the request because it is registered first and also matches:

routes.MapRoute(
                name: "errorhandler",
                template: "{controller}/{action}/{statusCode}"
                );

but since the param in the action method was id not statusCode, the model binder ignored it

I fixed it by changing the route to:

routes.MapRoute(
                name: "errorhandler",
                template: "Home/Error/{statusCode}"
                );

which is more specific to match so it falls through to the default route

I will fix it in all the starterkits and post here once I push the changes.

Thanks for letting me know!

joeaudette commented 7 years ago

ok, this issue is fixed in the starterkits

Thanks Again!

JanOlsmar commented 7 years ago

OK Thanks, I will be back if I find more.