我正在尝试使用数据模型创建一个视图 . 将其转换为字符串邮件 . 当我在localserver上运行它时工作正常但是当上传到azure时它会崩溃说:[ArgumentNullException:Value不能为null . 参数名称:view]

当不再在localserver上运行时,无法弄清楚为什么视图为null .

通过搞乱视图的路径,我可以在本地服务器上获得与天蓝色版本相同的错误消息

public static string MailViewToString(ControllerContext context, string viewName, TipsFormModel FormModel)
        {
            context.Controller.ViewData.Model = FormModel;

            using (var sw = new StringWriter())
            {
                var viewResult = ViewEngines.Engines.FindView(context, viewName, null);
                var viewContext = new ViewContext(context, viewResult.View, context.Controller.ViewData, context.Controller.TempData, sw);

                viewResult.View.Render(viewContext, sw);
                viewResult.ViewEngine.ReleaseView(context, viewResult.View);

                return sw.GetStringBuilder().ToString();
            }
        }

//控制器

[HttpPost]
    public ActionResult PostTip(TipsFormModel RecivedForm)
    {
    TipsList SpTipsList = new TipsList();

    RecivedForm.CurrentUser = Context.Web.CurrentUser.Title;

    var UploadedCv = RecivedForm.CV;
    var UploadedDoc = RecivedForm.OtherDocument;

    if (SavedJob != null)
    {
        RecivedForm.SelectedJob = SavedJob;
    }

    if (RecivedForm.CV != null)
    {
        UploadedCv = RecivedForm.CV;
    }

    if (RecivedForm.OtherDocument != null)
    {
        UploadedDoc = RecivedForm.OtherDocument;
    }


    //This function executes the tips and saves it into SP

    SpTipsList.InsertTipSp(RecivedForm, Context);

   string mailString = SendEmail.MailViewToString(this.ControllerContext, "~/Views/Home/MailView.cshtml", RecivedForm);

   SendEmail.SendMail(mailString, UploadedCv, UploadedDoc, Context);

    return View("PostTip");

}

//视图

@using (Html.BeginForm("PostTip", "Home", FormMethod.Post, new { id = "MainForm", enctype = "multipart/form-data" }))
    {
        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
            <label class="control-label">Kandidatens förnamn:</label>
            <div class="form-group vali">
                @Html.TextBox("FirstName", null, new { @class = "form-control input-lg", Name = "FirstName", id = "FirstName", placeholder = "Maria" })
            </div>

            <label class="control-label">Kandidatens efternamn:</label>
            <div class="form-group vali">
                @Html.TextBox("LastName", null, new { @class = "form-control input-lg", Name = "LastName", id = "LastName", placeholder = "Gustavsson" })
            </div>

            <label class="control-label">LinkedIn:</label>
            <div class="form-group vali">
                @Html.TextBox("LinkedIn", null, new { @class = "form-control input-lg", Name = "LinkedIn", id = "LinkedIn", placeholder = "https://se.linkedin.com/in/" })
            </div>

        </div>

        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
            <label class="control-label">Kandidatens Email:</label>
            <div class="form-group vali">
                @Html.TextBox("Email", null, new { @class = "form-control input-lg", Name = "Email", id = "Email", placeholder = "example@internet.com" })
            </div>

            <label class="control-label">Kandidatens telefonnr:</label>
            <div class="form-group vali">
                @Html.TextBox("PhoneNumber", null, new { @class = "form-control input-lg", Name = "PhoneNumber", id = "Phone", placeholder = "XXXXXXXXXX" })
            </div>

            <label class="control-label">Kön:</label>
            <div class="form-group">
                <div> @Html.DropDownList("Gender", new SelectList(Enum.GetValues(typeof(TipFormViewModel.Gender))), new { data_style="btn-default btn-lg" ,title = "Kön", @class = "selectpicker form-control" }) </div>
            </div>
        </div>


        <div class="clearfix"></div>
        
<div class="UploadDocument"> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"> <div class="form-group vali"> <label class="control-label">CV:</label> <input type="file" class="btn btn-default form-control" value="Browse" name="CV" />
</div> </div> <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"> <div class="form-group vali"> <label class="control-label">Andra dokument:</label> <input type="file" class="btn btn-default form-control" value="Browse" name="OtherDocument" />

</div> </div> </div> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> <div class="form-group vali txtarea"> <label class="control-label">Övrig information:</label> @Html.TextArea("Comment", null, new { @class = "form-control textAreaSize", placeholder = "Max 2000 tecken", rows = "8", maxlength = "2000" }) <div id="Counter"> Tecken kvar: 2000 / 2000 </div>
Ex. Vad har du för relation till kandidaten? Vad är hen duktig på? När kan vi bäst nå kandidaten? Övrig relevant information.
</div>

<div class="clearfix"></div> <div> <label> Är kandidaten medveten om ditt tips? </label> <div id="tipLabelNote">Notera att bonusen enbart betalas ut om den tipsade kandidaten är informerad i förväg.</div> @Html.CheckBox("Asked", new { @class = "checkbox-lg" }) <label class="checkbox-label" id="checkBoxQuest">JA</label>

<input type="submit" value="Skicka" class="btn custombtn-success slight-margin btn-lg" id="SubBtn"> <div>
<span class="login-fail">@ViewBag.DummyError</span> <span class="login-fail" id="ErrorValidation"></span> </div> </div> </div> <div class="clearfix"></div> } </div>

错误信息:

[ArgumentNullException:Value不能为null . 参数名称:view] System.Web.Mvc.ViewContext..ctor(ControllerContext controllerContext,IView view,ViewDataDictionary viewData,TempDataDictionary tempData,TextWriter writer)233 SpoRec.Models.SendEmail.MailViewToString(ControllerContext context,String viewPath,TipsFormModel FormModel)in在************ Mail \ SpoRec \ Controllers中的*********** \ SpoRec \ Models \ SendEmail.cs:61 SpoRec.Controllers.HomeController.PostTip(TipsFormModel RecivedForm) \ HomeController.cs:163 lambda_method(Closure,ControllerBase,Object [])104

System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller,Object []参数)14

System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary`2参数)169

System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext,ActionDescriptor actionDescriptor,IDictionary`2参数)27 ............ ......