Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
following code controller code
using l2.Models;

namespace l2.Controllers
{
public class cl2Controller : Controller
{
//
// GET: /cl2/
public ActionResult Getview()
{
Employee emp = new Employee();
emp.FirstName = "Sukesh";
emp.LastName = "Marla";
emp.Salary = 20000;
ViewData["Employee"] = emp;
return View("MyView");
}
}
}
this is model class code
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Salary { get; set; }
}
this is my view code i.e Myview.cshtml
XML
<div>
    @{
        l2.Models.Employee emp=(l2.Models.Employee)
            ViewData["Employee"];
    }

<b>Employee Details </b><br />
    Employee Name : @emp.FirstName@emp.LastName <br />
    Employee Salary: @emp.Salary.ToString("C")
</div>


here i am not getting any error but while execution time i am getting the following error
The view 'MyView' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/cl2/MyView.aspx
~/Views/cl2/MyView.ascx
~/Views/Shared/MyView.aspx
~/Views/Shared/MyView.ascx
~/Views/cl2/MyView.cshtml
~/Views/cl2/MyView.vbhtml
~/Views/Shared/MyView.cshtml
~/Views/Shared/MyView.vbhtml

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Posted

1 solution

Where Myview.cshtml is located in your project? Is that under the Views/cl2 folder?

 
Share this answer
 
Comments
sowjanyaroy 22-Jul-15 6:05am    
yes
Shmuel Zang 22-Jul-15 6:17am    
Is the provided code is the whole of your view's code? It doesn't contain some essential tags (html, body, etc...). Is that a partial view?
sowjanyaroy 22-Jul-15 6:34am    
i am using vs2012
sowjanyaroy 22-Jul-15 6:36am    
<div>
@{
l2.Models.Employee emp=(l2.Models.Employee)
ViewData["Employee"];
}

Employee Details <br />
Employee Name : @emp.FirstName@emp.LastName <br />
Employee Salary: @emp.Salary.ToString("C")
</div>
<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>MyView</title>
</head>
<body>
<div>
hai
</div>
</body>
</html>
please help me i am new to mvc5 its too confusing ..........
Shmuel Zang 22-Jul-15 6:51am    
Why the first div tag is outside of the body tag?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900