2

I have one ASP.NET MVC application which also has areas in it.

For short URL I have set route all actionmethods with short URLs in RouteConfig of areas like below.

//admin dashboard having short URL admin/dashboard
context.MapRoute(
            "admin_dashboard",
            "admin/dashboard",
            new { area = "admin", controller = "admin", action = "dashboard" }
        );

//student list having short URL admin/studentlist
        context.MapRoute(
            "student_list",
            "admin/studentlist",
            new { area = "admin", controller = "students", action = "List" }
        );

//new student having short URL admin/student/new
        context.MapRoute(
            "student_new",
            "admin/student/new",
            new { area = "admin", controller = "students", action = "RegisterStudent" }
        );

//edit student having short URL admin/student/id
        context.MapRoute(
            "student_edit",
            "admin/student/{id}",
            new { area = "admin", controller = "students", action = "RegisterStudent" }
        );

As you can see I have defined short URLs for all the actionmethods and it is also working fine except the last two which have calling the method but returns blank view.

        [Route("admin/student/{id}")]
        [Route("admin/student/new")]
        public ActionResult RegisterStudent(string Id)
        {
         ....mycode
         return View("RegisterStudent", mymodel);
        }

The problem is it is calling the method without any error, but it is not returning the view. It returns the blank view. Why does this happen, did I make any mistake?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
3 rules
  • 1,359
  • 3
  • 26
  • 54

2 Answers2

1

If your request is going to your action method, then there is no problem in routing. If your action is returning a blank View then, there must be some problem with View itself.

Sunny Verma
  • 107
  • 4
0

Id is an integer by default in route. you are considering it as a string.

  • Didn't get your point. Can you please elaborate! I can't change the string to int I have to make it as it is and access the action method and it is accessing right now the method but return a blank view. I want a view in return. – 3 rules Nov 01 '18 at 11:02
  • Sorry I have provided the code as much as I can share from the application. I only have one form that consists of fields that's it. It was working normally before I changed the url. But as I have to short the url as requirement I am doing this. – 3 rules Nov 01 '18 at 11:12
  • I just want to know if it was working fine before changing the URL why it is not returning the page now as I haven't changed anything except setting the URL only. View name is the same as the name of the actionmethod. – 3 rules Nov 01 '18 at 11:14