ibnhamza
ibnhamza

Reputation: 871

View not found after returning parameters to action

My controller works fine and returns the right view when hit without a parameter, however when i pass in parameter to the action, the view is not found. The controller is in an area called Admin and the route registration is displayed below

public class AdminAreaRegistration : AreaRegistration 
{
    public override string AreaName 
    {
        get { return "Admin"; }
    }

    public override void RegisterArea(AreaRegistrationContext context) 
    {
        context.MapRoute(
            "Admin_default",
            "Admin/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional },
            namespaces: new[] { "ZedvancePortal.Areas.Admin.Controllers" }
        );
    }
}

The RouteConfig.cs in the appstart folder

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            namespaces: new[] { "ZedvancePortal.Controllers" }
        );
    }
}

The area is registered in the Global.asax page. This is the controller action below.

public ActionResult Review(DateTime? start, DateTime? end)
{
    var model = _db.Applications.Include(a => a.ApplicationStatus).OrderByDescending(a => a.ApplicationDate);
    if (start != null && end != null)
    {
        model = model.Where(a => a.ApplicationDate >= start && a.ApplicationDate <= end).OrderByDescending(a=>a.ApplicationDate);
    }
    return View(model.ToList());
}

On first load, without the start and end parameters passed from the Review.cshtml view, it loads correctly. However when i pass in those parameters and try to return the parameter filtered result to that same view i get the error

The view 'Review' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/ApplicationReview/Review.aspx ~/Views/ApplicationReview/Review.ascx ~/Views/Shared/Review.aspx ~/Views/Shared/Review.ascx ~/Views/ApplicationReview/Review.cshtml ~/Views/ApplicationReview/Review.vbhtml ~/Views/Shared/Review.cshtml ~/Views/Shared/Review.vbhtml

What could be the problem?

Upvotes: 0

Views: 288

Answers (1)

Rajan Kali
Rajan Kali

Reputation: 12953

The Problem is Because if you mention only Name of View,it results in Ambiguity because it found an Web service and View,and will an Error to avoid Confusion

Try using Full Path of View i.e like

return View("~/Views/ApplicationReview/Review.cshtml",model.ToList());

Upvotes: 1

Related Questions