【发布时间】:2014-04-21 12:33:15
【问题描述】:
我是第一次使用 MVC4 编程。
我有一个简单的文本框,想从 Controller 访问它。
我完成了以下操作:
家庭控制器:
[HttpPost]
public ActionResult getValues(ModelClass mClass)
{
mClass.userName = "Hi!!, I am Sagar";
return Content(mClass.userName);
}
Index.cshtml:
@model KendoUIMvcApplication.Models.ModelClass
@using (Html.BeginForm("Index", "Home", FormMethod.Post, null))
{
@Html.TextBoxFor(model=>model.userName.ToString())
}
模型类:
namespace KendoUIMvcApplication.Models
{
public class ModelClass
{
public string userName
{
get;
set;
}
}
}
它给了我错误:
传入字典的模型项是类型 'System.Collections.Generic.List`1[System.String]',但这 字典需要类型的模型项 'KendoUIMvcApplication.Models.ModelClass'。
新错误:
视图“嗨!!,我是 Sagar”或其主人未找到,或者没有视图引擎支持搜索的位置。搜索了以下位置: ~/Views/Home/嗨!!,我是 Sagar.aspx ~/Views/Home/嗨!!,我是 Sagar.ascx ~/Views/Shared/嗨!!,我是 Sagar.aspx ~/Views/Shared/嗨!!,我是 Sagar.ascx ~/Views/Home/嗨!!,我是 Sagar.cshtml ~/Views/Home/嗨!!,我是 Sagar.vbhtml ~/Views/Shared/嗨!!,我是 Sagar.cshtml ~/Views/Shared/嗨!!,我是 Sagar.vbhtml
说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.InvalidOperationException:未找到视图“嗨!!,我是 Sagar”或其主人,或者没有视图引擎支持搜索的位置。搜索了以下位置: ~/Views/Home/嗨!!,我是 Sagar.aspx ~/Views/Home/嗨!!,我是 Sagar.ascx ~/Views/Shared/嗨!!,我是 Sagar.aspx ~/Views/Shared/嗨!!,我是 Sagar.ascx ~/Views/Home/嗨!!,我是 Sagar.cshtml ~/Views/Home/嗨!!,我是 Sagar.vbhtml ~/Views/Shared/嗨!!,我是 Sagar.cshtml ~/Views/Shared/嗨!!,我是 Sagar.vbhtml
来源错误:
在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。
堆栈跟踪:
[InvalidOperationException: The view 'Hi!!, I am Sagar' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Hi!!, I am Sagar.aspx
~/Views/Home/Hi!!, I am Sagar.ascx
~/Views/Shared/Hi!!, I am Sagar.aspx
~/Views/Shared/Hi!!, I am Sagar.ascx
~/Views/Home/Hi!!, I am Sagar.cshtml
~/Views/Home/Hi!!, I am Sagar.vbhtml
~/Views/Shared/Hi!!, I am Sagar.cshtml
~/Views/Shared/Hi!!, I am Sagar.vbhtml]
System.Web.Mvc.ViewResult.FindView(ControllerContext context) +506
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +230
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +39
System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +74
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +388
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +72
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +303
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +155
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +184
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +136
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +40
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +47
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +151
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +47
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +151
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +45
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +47
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +151
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629708
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
【问题讨论】:
-
你想做什么?
标签: c# asp.net .net asp.net-mvc-4