-1

I created a custom Model i.e. to support my Razor View. Then I created a controller as following`namespace MyCandidate.Controllers

public class CandidateViewModelController : Controller
{
    //
    // GET: /CandidateViewModel/

    public ActionResult Index()
    {
        return View();
    }

}

I also have the following statement in my _Layout.cshtml

@Html.ActionLink("Canid", "Index", "CandidateViewModel")

Next i created a view and the very first statement of the view is

@model MyCandidate.Models.CandidateViewModel

when i run my project i get the following error

The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:

I spent more than 3 hours but could not figure out?

2 Answers 2

0
  1. your Index() not get any parameters, but you send "CandidateViewModel") add Index(string input) method with attribute [HttpGet] to controller.

  2. this error meen you haven't view "Index" in "Views/CandidateViewModel/Index.cshtml".

  3. Maybe you delete master page files (_ViewSrat, _Layout)

  4. Or you made a mistake when you change your routes

0

Change your ActionLink to:

@Html.ActionLink("Canid", "Index")

If you want to pass any data to View , you can also use ViewBag:

// Controller :
ViewBag.CandidateValues = CandidateViewModelData;

// View 
@Html.Label("LabelName", (CandidateViewModel) ViewBag.CandidateValues.FiledName);
7
  • thanks @Amir978. I have many questions as I just started MVC3 last week. I mean moving from Asp Forms and Nhibernate to EF4.1 and MVC3. Ok, if you could help me with another question. Most of the times our views are based on multiple objects or in other words underlying tables. So do we need to first model it i.e. to make a custom class with properties per each input field and then base our view on this model. Also if you could direct me to some useful link.
    – akberali
    Oct 17, 2011 at 5:58
  • @akberali Be better if you will create viewmodel for every view with some amount of properties that you need (se my answer here) stackoverflow.com/questions/7539069/… Oct 17, 2011 at 6:10
  • @akberali I'll be glad to help you as much as I can. First of all I suggest you to watch all Pluralsight MVC movies in ASP.NET website as Free! (beta.asp.net/mvc ) You will find many answers of your questions there. Please do not hesitate to ask your questions. And regards the Models, yes it's very good idea to have a model(class) for each group of data you work with and the point is you can access them in Views(Strongly Type model)
    – Amir978
    Oct 19, 2011 at 0:56
  • thanks @Amir978. do i always need a separate controller as well i.e. I should always have a set of Controller, Model and View. I am asking this question as I have a view ABC.cshtm based on a model class ABCModel.cs. I don't need a controller for this. So how do I call ABC.cshtml from the action method of another controller called XYZController. I tried return View("ABC") and ` return View ("ABC", new ABCModel());` but i am getting error
    – akberali
    Oct 20, 2011 at 3:03
  • let me add that my View ABC is in different folder structure i.e. not in where other views for XYZController reside. When I copy the view ABC to the folder structure of XYZController then it works
    – akberali
    Oct 20, 2011 at 3:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.