Home > Enterprise >  keeping view name and corresponding controller method name different
keeping view name and corresponding controller method name different

Time:11-13

I have a controller method named CreatePANApplication but I have created view page for this named as PANApplication. Now when I am trying to call this method from another view page as:

// dataTable code block
<td>    
    @Html.ActionLink("PAN Application", "CreatePANApplication", new { id = item.PANKey }, new { @class = "btn btn-warning" })
</td>

getting error as:

The view 'CreatePANApplication' or its master was not found or no view engine supports the searched locations.

It means that I should not keep my controller name and corresponding view page name different. But many times we have to change the view page name, what can we do at that time?

Controller class:

public ActionResult CreatePANApplication(int? id)
        {
            try
            {
                if (id == null)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }
                var data = (from z in db.PANModels
                            where z.PANKey == id
                            select z).ToList();

                if (data == null)
                {
                    return HttpNotFound();
                }
                return View(data);
            }
            catch (Exception)
            {

                throw;
            }
        }

CodePudding user response:

if your view is still in the folder that is named as a controller, or you put your view in a Shared folder, you can use this

 return View("PANApplication", data);

but if your view is in different folder you will have to use the full path

return View(" ~/Views/folder/PANApplication.cshtml", data);
  • Related