-1

In .net core, is it not possible to use mvc routing? I used this:

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Landing}/{action=Index}/{id?}");
        });

and my action:

    public IActionResult Index(string profileId)
    {
        this.ProfileId = profileId;

        return View();
    }

but if I used url something like /Profile/index?profileId=1 it works fine but if I use /Profile/index/1 the action is not works. means profileId is null. Why that happens with me - is there anything I am missing?

I try to use [FromQuery] and [FromRoute] in index method but that is not also working.

halfer
  • 18,701
  • 13
  • 79
  • 158
nayan chowdhury
  • 245
  • 8
  • 24

1 Answers1

2

Your route parameter is named id (not profileId) so either change the method to

public IActionResult Index(string id)

so it matches the route, or you can modify the the route definition to

template: "{controller=Landing}/{action=Index}/{profileId?}");

but that may affect other methods you have