C# asp.net mvc:Error1:值不能为null

C# asp.net mvc:Error1:值不能为null,c#,asp.net-mvc,asp.net-mvc-3,C#,Asp.net Mvc,Asp.net Mvc 3,我有一个注册页面。它在我的本地计算机上工作,但在我部署到生产环境之后。不断收到以下错误消息 Server Error in '/' Application. Error1: Value cannot be null. Parameter name: view Description: An unhandled exception occurred during the execution of t

我有一个注册页面。它在我的本地计算机上工作,但在我部署到生产环境之后。不断收到以下错误消息

            Server Error in '/' Application.

            Error1: Value cannot be null.
            Parameter name: view

            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. 

            Exception Details: System.Exception: Error1: Value cannot be null.
            Parameter name: view

            Source Error: 

            An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

            Stack Trace: 


            [Exception: Error1: Value cannot be null.
            Parameter name: view]
               Smoothie.Web.Controllers.AccountController.Signup(UserRegisterViewModel user, String returnUrl) +662
               lambda_method(Closure , ControllerBase , Object[] ) +149
               System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
               System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +181
               System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
               System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +56
               System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +256
               System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +22
               System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +190
               System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +311
               System.Web.Mvc.Controller.ExecuteCore() +105
               System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +88
               System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
               System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
               System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
               System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
               System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
               System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31
               System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
               System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
               System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
               System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
               System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9690172
               System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
这是我从代码中删除try-catch后的新堆栈跟踪

        Value cannot be null.
        Parameter name: view

        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. 

        Exception Details: System.ArgumentNullException: Value cannot be null.
        Parameter name: view

        Source Error: 

        An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

        Stack Trace: 


        [ArgumentNullException: Value cannot be null.
        Parameter name: view]
           System.Web.Mvc.ViewContext..ctor(ControllerContext controllerContext, IView view, ViewDataDictionary viewData, TempDataDictionary tempData, TextWriter writer) +205
           Smoothie.Web.Controllers.AccountController.GetWelcomeEmail() +178
           Smoothie.Web.Controllers.AccountController.Signup(UserRegisterViewModel user) +288
           lambda_method(Closure , ControllerBase , Object[] ) +106
           System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
           System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +181
           System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
           System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +56
           System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +256
           System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +22
           System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +190
           System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +311
           System.Web.Mvc.Controller.ExecuteCore() +105
           System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +88
           System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
           System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
           System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
           System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
           System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
           System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31
           System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
           System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
           System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
           System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
           System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9690172
           System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
值不能为空。
参数名称:视图
描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源。
异常详细信息:System.ArgumentNullException:值不能为null。
参数名称:视图
源错误:
在执行当前web请求期间生成了未经处理的异常。有关异常的起源和位置的信息可以使用下面的异常堆栈跟踪来识别。
堆栈跟踪:
[ArgumentNullException:值不能为null。
参数名称:视图]
System.Web.Mvc.ViewContext..ctor(ControllerContext ControllerContext,IView视图,ViewDataDictionary viewData,TempDataDictionary tempData,TextWriter编写器)+205
Smoothie.Web.Controllers.AccountController.GetWelcomeEmail()+178
Smoothie.Web.Controllers.AccountController.Signup(UserRegisterViewModel用户)+288
lambda_方法(闭包、控制器基、对象[])+106
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase控制器,对象[]参数)+14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext ControllerContext,IDictionary`2参数)+181
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext ControllerContext,ActionDescriptor ActionDescriptor,IDictionary`2参数)+27
System.Web.Mvc.c__显示类15.b__12()+56
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter筛选器、ActionExecutingContext预文本、Func`1 continuation)+256
System.Web.Mvc.c__显示类17.b__14()+22
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext ControllerContext,IList`1筛选器,ActionDescriptor ActionDescriptor,IDictionary`2参数)+190
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext ControllerContext,String actionName)+311
System.Web.Mvc.Controller.ExecuteCore()+105
System.Web.Mvc.ControllerBase.Execute(RequestContext-RequestContext)+88
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext RequestContext)+10
System.Web.Mvc.c__显示类b.b__5()+34
System.Web.Mvc.Async.c__显示类1.b__0()+19
System.Web.Mvc.Async.c_uuuudisplayClass8`1.b_uuuu7(IAsyncResult)+10
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+55
System.Web.Mvc.c_uuudisplayClasse.b_uuud()+31
System.Web.Mvc.SecurityUtil.b___0(操作f)+7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(操作)+23
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+59
System.Web.Mvc.MvcHandler.System.Web.IHTTPassynchandler.EndProcessRequest(IAsyncResult结果)+9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+9690172
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+155

根据最新的调用堆栈,看起来
GetWelcomeEmail()
中缺少视图,这导致
view
在ViewContexts构造函数中为空。

我在本地计算机上尝试了这两种方法,它们都有效。然后在生产中试了两次,结果都不起作用。一定是别的。我不知道你说的我的路线是什么意思。路线是:/Account/Signup,我也在底部发布了查看页面,希望它能有所帮助。@feelexit-可能值得删除这些旧评论,因为它们是我之前发布的答案。不确定我的路线是什么意思。路线是:/Account/Signup,我也在底部发布了视图页面,希望它能有所帮助。@Steve,第662行public virtual ActionResult Signup(UserRegisterViewModel user,string returnUrl)向我们展示模型定义plz@Steve,我在文章的底部添加了模型。你永远不想在catch中重新显示一个异常,它会破坏stacktrace。将抛出新异常更改为仅抛出;给我们看看新的stacktrace
            @model Smoothie.Domain.ViewModels.UserRegisterViewModel
            @using (Ajax.BeginForm("Signup", "Account", new AjaxOptions { OnSuccess = "onSignupSuccess", OnFailure = "onSignupFailure" }))
            {

                @Html.AntiForgeryToken()
                @Html.Hidden("returnUrl", null, new { value = @Request.QueryString["returnUrl"] })    
                <div class="signupForm">
                    <div>@Html.ValidationSummary("", new { @id = "signupSummary" })</div>
                    <div class="row">
                        <label for="Email">
                            Display Name:</label>
                        @Html.EditorFor(m => m.DisplayName)
                    </div>
                    <div class="row">
                        <label for="Email">
                            Email Address:</label>
                         @Html.TextBoxFor(m => m.Email, new {@class = "text-box", autocomplete = "off" })
                    </div>
                    <div class="row">
                        <label for="Password">
                            Password:</label>
                        @Html.TextBox("Password", null, new { @class = "registerPassword text-box", type = "password", autocomplete = "off" })
                    </div>
                    <div class="row">
                        <label>
                            &nbsp;</label>
                        <div class="registerChecker">
                        </div>
                    </div>
                    <div class="row">
                        <label>
                            &nbsp;</label>
                        <input type="image" src="@Links.Content.images.btn_sign_up_png" style="width: 91px; height: 33px;" value="Create" />
                    </div>
                </div>
            }
            using System.ComponentModel.DataAnnotations;

            namespace Smoothie.Domain.ViewModels
            {
                public class UserRegisterViewModel
                {
                    [Required(ErrorMessage = "Email is required")]
                    [StringLength(255, ErrorMessage = "Email must be 50 characters or fewer")]
                    [RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Your Email address is invalid")]
                    public string Email { get; set; }

                    [Required(ErrorMessage = "Display name is required")]
                    [StringLength(25, MinimumLength = 2, ErrorMessage = "Display name must be between 2 and 25 characters")]
                    public string DisplayName { get; set; }

                    [DataType(DataType.Password)]
                    [Required(ErrorMessage = "Password is required")]
                    [StringLength(25, MinimumLength = 8, ErrorMessage = "Password must be between 8 and 25 characters")]
                    public string Password { get; set; }
                }
            }
        Value cannot be null.
        Parameter name: view

        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. 

        Exception Details: System.ArgumentNullException: Value cannot be null.
        Parameter name: view

        Source Error: 

        An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

        Stack Trace: 


        [ArgumentNullException: Value cannot be null.
        Parameter name: view]
           System.Web.Mvc.ViewContext..ctor(ControllerContext controllerContext, IView view, ViewDataDictionary viewData, TempDataDictionary tempData, TextWriter writer) +205
           Smoothie.Web.Controllers.AccountController.GetWelcomeEmail() +178
           Smoothie.Web.Controllers.AccountController.Signup(UserRegisterViewModel user) +288
           lambda_method(Closure , ControllerBase , Object[] ) +106
           System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
           System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +181
           System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
           System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +56
           System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +256
           System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +22
           System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +190
           System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +311
           System.Web.Mvc.Controller.ExecuteCore() +105
           System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +88
           System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
           System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
           System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
           System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
           System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
           System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31
           System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
           System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
           System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
           System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
           System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9690172
           System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155