如何在asp.net mvc5中查看视图 [英] how to get out put of view in asp.net mvc5
问题描述
以下代码控制器代码
使用l2.Models;
命名空间l2.Controllers
{
公共类cl2Controller:控制器
{
//
// GET:/ cl2 /
public ActionResult Getview()
{
员工emp =新员工();
emp.FirstName =Sukesh;
emp.LastName =Marla;
emp.Salary = 20000;
ViewData [Employee] = emp;
返回查看(MyView);
}
}
}
这是模型类代码
公共类员工
{
public string FirstName {get;组; }
公共字符串LastName {get;组; }
public int Salary {get;组; }
}
这是我的查看代码,即Myview.cshtml
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
<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>
这里我没有收到任何错误但是执行时间我得到以下错误
未找到视图MyView或其主文件或视图引擎没有支持搜索的位置。搜索了以下位置:
~ / Views / cl2 / MyView.aspx
~ / Views / cl2 / MyView.ascx
~ /观看/分享/ MyView.aspx
~ / Views / Shared / MyView.ascx
~ / Views / cl2 / MyView.cshtml
~ /Views/cl2/MyView.vbhtml
~ / Views / Shared / MyView.cshtml
~ / Views / Shared / MyView.vbhtml
描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
推荐答案
Myview.cshtml
位于您的项目中?是在Views / cl2
文件夹下吗?
Where
Myview.cshtml
is located in your project? Is that under theViews/cl2
folder?
这篇关于如何在asp.net mvc5中查看视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!