Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从应用程序外部直接调用ASP.NET MVC web应用程序中的特定视图的正确方法是什么?_C#_Html_Asp.net Mvc - Fatal编程技术网

C# 从应用程序外部直接调用ASP.NET MVC web应用程序中的特定视图的正确方法是什么?

C# 从应用程序外部直接调用ASP.NET MVC web应用程序中的特定视图的正确方法是什么?,c#,html,asp.net-mvc,C#,Html,Asp.net Mvc,所以,我想确保我做的是正确的,因为我有一个奇怪的问题,我不能弄清楚。我有一个ASP.NET web应用程序,用于跟踪制造环境中的质量问题。创建新记录后,将向相应人员发送电子邮件通知。在那封电子邮件中,我想包含一个链接,为那个特定的记录打开一个特定的视图 在电子邮件中,我有以下超链接: var link = "<a href = "\"\\webapp-dev\\Nonconformance\\AP\\Details_APInt\\" + nonconform.ID + "\">Cli

所以,我想确保我做的是正确的,因为我有一个奇怪的问题,我不能弄清楚。我有一个ASP.NET web应用程序,用于跟踪制造环境中的质量问题。创建新记录后,将向相应人员发送电子邮件通知。在那封电子邮件中,我想包含一个链接,为那个特定的记录打开一个特定的视图

在电子邮件中,我有以下超链接:

var link = "<a href = "\"\\webapp-dev\\Nonconformance\\AP\\Details_APInt\\" + nonconform.ID + "\">Click here to view details</a>";
以下是堆栈跟踪:

[NullReferenceException: Object reference not set to an instance of an object.] 
    ASP._Page_Views_ap_Details_APInt_cshtml.Execute() in C:\Nonconformance\Views\ap\Details_APInt.cshtml:5
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +251
    System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +147
    System.Web.WebPages.StartPage.ExecutePageHierarchy() +87
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +106
    System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +374
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +87
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +831
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +81
    System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
    System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
    System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +43
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +395
    System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +197
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +128
详细信息\u APExt(视图):


我能想到的唯一一件事是,它使用的是一个ViewModel,而不仅仅是一个模型,但我不明白,如果在渲染视图之前成功填充它,为什么这很重要?

URL应该始终具有前斜杠。即使这不是这个问题的原因,也不应该有任何反斜杠。您的第二个示例(带正斜杠)是正确的。仔细检查电子邮件中打印的URL与已知的、好的URL之间的差异。谢谢你们的评论。请看我提供的其他信息。我没有读你的帖子,只是标题。但我只想指出,在ASP.NETMVC中,您不会“导航到视图”。URL将通过称为路由的概念映射到操作方法。然后,操作方法将决定如何处理请求,包括返回哪个视图。VS可能错误地识别ViewBag上的故障。您的视图是否希望控制器提供模型?控制器操作是否正确接收参数?如果直接导航到浏览器中的链接会发生什么情况?URL应始终具有前斜杠。即使这不是这个问题的原因,也不应该有任何反斜杠。您的第二个示例(带正斜杠)是正确的。仔细检查电子邮件中打印的URL与已知的、好的URL之间的差异。谢谢你们的评论。请看我提供的其他信息。我没有读你的帖子,只是标题。但我只想指出,在ASP.NETMVC中,您不会“导航到视图”。URL将通过称为路由的概念映射到操作方法。然后,操作方法将决定如何处理请求,包括返回哪个视图。VS可能错误地识别ViewBag上的故障。您的视图是否希望控制器提供模型?控制器操作是否正确接收参数?如果直接导航到浏览器中的链接,会发生什么情况?
[NullReferenceException: Object reference not set to an instance of an object.] 
    ASP._Page_Views_ap_Details_APInt_cshtml.Execute() in C:\Nonconformance\Views\ap\Details_APInt.cshtml:5
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +251
    System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +147
    System.Web.WebPages.StartPage.ExecutePageHierarchy() +87
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +106
    System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +374
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +87
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +831
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +81
    System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
    System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
    System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +43
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +395
    System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +197
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +128
var link = "<a href = "\"\\webapp-dev\\Nonconformance\\AP\\Details_APInt\\" + nonconform.ID + "\">Click here to view details</a>";
link = "<a href = \"http://webapp-dev/nonconformance/ap/Details_APInt/" + nonconform.ID + "\">Click here to view</a>";
link = "<a href = \"http://webapp-dev/nonconformance/ap/Details_APInt/" + nonconform.ID + "\">Click here to view</a>";
    public ActionResult Details_APInt(int id)
    {            
        var result = GetUserInfo();

        ViewBag.ReplyFrom = result.Properties["givenname"][0].ToString() + " " + result.Properties["sn"][0].ToString();

        TempData["FirstName"] = result.Properties["givenname"][0].ToString();

        var nc = db.Nonconforms.Find(id);

        var defect = (from x in db.Defects_Caused
                      where x.Nonconform_ID == nc.Nonconform_ID
                      select x).FirstOrDefault();

        var fromDept = (from f in db.Workcenters
                    where f.ID == nc.From_WC
                    select f).FirstOrDefault();

        var toDept = (from x in db.Workcenters
                      where x.ID == nc.To_Dept
                      select x).FirstOrDefault();

        var type = (from t in db.Nonconform_Types
                    where t.ID == nc.Type
                    select t).FirstOrDefault();

        nc.From = fromDept.Name;
        nc.To = toDept.Name;
        nc.TypeName = type.Name;

        var rolls = (from x in db.Affected_Rolls
                     where x.Nonconform_ID == nc.Nonconform_ID
                     select x).ToList();

        List<Dictionary<string, string>> affectedRolls = new List<Dictionary<string, string>>();

        foreach (var roll in rolls)
        {
            affectedRolls.Add(GetMESInfo(roll.AC));
        }

        ViewBag.affectedRolls = affectedRolls;

        nc.Replies = (from r in db.Replies
                      where r.Nonconform_ID == nc.Nonconform_ID
                      select r).OrderByDescending(x => x.Reply_Date).ToList();

        var vm = new ViewModel();
        vm.Defect_Caused = defect;
        vm.Nonconform = nc;

        ViewBag.Time = vm.Nonconform.Date.ToShortTimeString().ToString();
        ViewBag.Phone = result.Properties["telephonenumber"][0].ToString();

        return View(vm);
    }
    public ActionResult Details_APExt(int id)
    {
        var result = GetUserInfo();

        ViewBag.ReplyFrom = result.Properties["givenname"][0].ToString() + " " + result.Properties["sn"][0].ToString();

        TempData["FirstName"] = result.Properties["givenname"][0].ToString();

        var nc = db.Nonconforms.Find(id);

        var dept = (from f in db.Workcenters
                    where f.ID == nc.From_Dept
                    select f).FirstOrDefault();

        var type = (from t in db.Nonconform_Types
                    where t.ID == nc.Type
                    select t).FirstOrDefault();

        nc.From = dept.Name;
        nc.TypeName = type.Name;

        var rolls = (from x in db.Affected_Rolls
                     where x.Nonconform_ID == nc.Nonconform_ID
                     select x).ToList();

        List<Dictionary<string, string>> affectedRolls = new List<Dictionary<string, string>>();

        foreach (var roll in rolls)
        {
            affectedRolls.Add(GetMESInfo(roll.AC));
        }

        ViewBag.affectedRolls = affectedRolls;

        nc.Replies = (from r in db.Replies
                      where r.Nonconform_ID == nc.Nonconform_ID
                      select r).OrderByDescending(x => x.Reply_Date).ToList();

        return View(nc);
    }
@model Nonconformance.Models.ViewModel
@model Nonconformance.Models.Nonconform