在本文中,我们将详细介绍asp.net-mvc–App_Web_*.dll中的System.NullReferenceException的各个方面,并为您提供关于aspnetcorev2.dll未能加
在本文中,我们将详细介绍asp.net-mvc – App_Web _ * .dll中的System.NullReferenceException的各个方面,并为您提供关于aspnetcorev2.dll未能加载的相关解答,同时,我们也将为您带来关于.Net Core System.NullReferenceException 中的 Api、ASP.NET Core 连接两个表模型返回 NullReferenceException、asp.net – ExecuteScalar抛出NullReferenceException、asp.net – MVC DropDownListFor – NullReferenceException被usercode取消了的有用知识。
本文目录一览:- asp.net-mvc – App_Web _ * .dll中的System.NullReferenceException(aspnetcorev2.dll未能加载)
- .Net Core System.NullReferenceException 中的 Api
- ASP.NET Core 连接两个表模型返回 NullReferenceException
- asp.net – ExecuteScalar抛出NullReferenceException
- asp.net – MVC DropDownListFor – NullReferenceException被usercode取消了
asp.net-mvc – App_Web _ * .dll中的System.NullReferenceException(aspnetcorev2.dll未能加载)
我的MVC应用程序似乎工作完美,除了一个视图页面。
有问题的视图页面(组织/编辑)在页面上的每个代码项目上获得“NullReferenceException”。无论是Html.TextBoxFor()还是HTML.AntiForgeryToken()。
我有我的模型,视图和控制器在这里列出了我认为是相关的另一个问题 – http://stackoverflow.com/questions/26475866/dropdownlistfor-null-reference-error
如下所示,我的模型确实有信息。此屏幕捕获是在控制器内的“返回视图(”编辑“,型号)”中获取的。
异常详细信息
- Source = App_Web_zu4jlld0 - StackTrace = at ASP._Page_Views_Organization_Edit_vbhtml.Execute() in C:\Users\mtaylor\Projects\Check Im Here\mtaylor-branch\CheckImHere_v2\CheckImHereMVC\Views\Organization\Edit.vbhtml:line 16 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at System.Web.WebPages.StartPage.RunPage() at System.Web.WebPages.StartPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext,TextWriter writer,WebPageRenderingBase startPage) at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext,Object instance) at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext,TextWriter writer) at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext,ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.<>c__displayClass1a.<InvokeActionResultWithFilters>b__17() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter,ResultExecutingContext preContext,Func`1 continuation)
视图
@ModelType CheckImHereMVC.OrganizationEditviewmodel @Using Html.BeginForm("Edit","Organization",FormMethod.Post) @Html.AntiForgeryToken() 'get errors here @Html.ValidationSummary(True) 'get errors here @Html.TextBoxFor(Function(model) model.organizationSub.subName,New With {.}) 'and errors here End Using
有一件事我注意到,如果我注释掉我的’textBoxfor’,我的错误将发生在’ValidationSummary()’,如果我注释掉我的’ValidationSummary()’,那么我的错误将发生在’AntiForgeryToken()’。
所以似乎错误只发生在最后一个可能的代码区域。
解决方法
任何人找到这个:
尝试在错误后面注释下一个代码行。
@ModelType CheckImHereMVC.OrganizationEditviewmodel @Using Html.BeginForm("Edit",FormMethod.Post) @Html.AntiForgeryToken() @Html.ValidationSummary(True) @Html.TextBoxFor(Function(model) model.organizationSub.subName,New With {.}) @Html.TextBoxFor(Function(model) model.organizationSub.subTitle,New With {.}) <img src="@Url.Content(Model.img.imgPath)" alt="IMAGES"/> 'commenting out this line fixed my issue End Using
在上面的情况下,我会在model.organizationSub.subTitle上得到错误。如果我评论了这行,我会在model.organizationSub.subName行上收到错误。然后我发现所提到的链接,并注释掉了我的所有TextBoxFors之后的行。这解决了我的问题。
从链接:“有时编译器不能指出在剃刀视图中具有特定类型的错误的精确行可能是因为它不能将它们的行号保留在堆栈跟踪或某处,我发现这种情况与Null引用异常,当null为通过Url.Content。
因此,当您没有在堆栈跟踪中显示的行中没有得到任何错误时,可以检查razor视图中的下一个C#语句。
.Net Core System.NullReferenceException 中的 Api
如何解决.Net Core System.NullReferenceException 中的 Api?
我刚刚开始学习 Api''s 并开始构建一个简单的。 我构建了这个 EmployeeController:
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
namespace ApiHandsOn1.Controllers
{
[Route("api/Employee")]
[ApiController]
public class EmployeeController : Controller
{
List<Employee> _employeeList = new List<Employee>()
{
new Employee()
{
Id=1,Name= "abc def",Salary=20000,Permanent= true,//Department= { Id = 1,Name = "Payroll"},Skills ={new Skill{ Id= 1,Value= "HTML"},new Skill{ Id= 2,Value="CSS"},new Skill{ Id= 1,Value= "JS"} },DateOfBirth = new DateTime(01/03/2002)
},new Employee()
{
Id=2,Name= "ghi jkl",Salary=25000,Permanent= false,//Department= { Id = 2,Name = "HR"},DateOfBirth = new DateTime(15/08/2005)
}
};
public EmployeeController()
{
}
private List<Employee> GetStandardEmployeeList()
{
return _employeeList;
}
// GET: EmployeeController
[HttpGet]
[Route("GetEmployees")]
[ProducesResponseType(StatusCodes.Status200OK)]
public List<Employee> GetStandard()
{
List<Employee> empList=GetStandardEmployeeList();
return empList;
}
}
}
我已经为各个类构建了模型。 但是当我在 Swagger 上点击执行时,它会抛出一个异常(在 _employeeList):
System.NullReferenceException: ''未将对象引用设置为对象的实例。''
我错过了什么?
解决方法
您需要像这样初始化 Skills
属性:
Skills = new List<Skill>(){new Skill{},new Skill{}}
正如@smoksnes 提到的,你应该把你的值放在 DateTime
初始化中的文字之间
ASP.NET Core 连接两个表模型返回 NullReferenceException
从类中删除集合初始化并按以下方式添加顺序:
public void Test(User user)
{
_context.Orders.Add(new Order() { Test = "test",User = user });
_context.SaveChanges();
}
,
试试这个:
public void Test(User user)
{
_context.Orders.Add(new Order { Test = "test",UserId=user.Id});
_context.SaveChanges();
}
asp.net – ExecuteScalar抛出NullReferenceException
selectedPassengerID = 0; //sqlCommand command = GenericDataAccess.CreateCommand(); // 2nd test string connectionString = ""; sqlConnection conn; connectionString = ConfigurationManager. ConnectionStrings["ConnST-MHM"].ConnectionString; conn = new sqlConnection(connectionString); sqlCommand command = new sqlCommand(); command.CommandType = CommandType.StoredProcedure ; command.Connection = conn; command.CommandText = "SearchForPassenger"; sqlParameter param; param = command.CreateParameter(); param.ParameterName = "@name"; param.Value = pName; // Session[""]; param.DbType = DbType.String; command.Parameters.Add(param); param = command.CreateParameter(); param.ParameterName = "@flightDate"; param.Value = date; param.DbType = DbType.String; command.Parameters.Add(param); param = command.CreateParameter(); param.ParameterName = "@ticketNo"; param.Value = ticketNumber; param.DbType = DbType.Int32; command.Parameters.Add(param); int item; command.Connection.open(); item = (int)command.ExecuteScalar();
解决方法
object temp = cmnd.ExecuteScalar(); if ((temp == null) || (temp == dbnull.Value)) return -1; return (int)temp;
我知道你已经输入了很多代码,但我认为这确实是你问题的本质.祝你好运!
asp.net – MVC DropDownListFor – NullReferenceException被usercode取消了
How to write a simple Html.DropDownListFor()?我正在尝试BaraT的解决方案,但面临NullReferenceException的错误.以下是我的代码.
<%: Html.DropDownListFor(model => model.CreditCardType,new SelectList( new List<Object>{ new { value = 0,text="VISA"},new { value = 1,text="Master"},new { value = 2,text="Debit"}},"value","text",Model.CreditCardType) )%>
ErrorDetail:未将对象引用设置为对象的实例.
谁能帮帮我吗?我可能会犯小错误但无法修复它.
解决方法
model.CreditCardType,new SelectList( new List{ new { value = 0,"VISA") )%>
今天的关于asp.net-mvc – App_Web _ * .dll中的System.NullReferenceException和aspnetcorev2.dll未能加载的分享已经结束,谢谢您的关注,如果想了解更多关于.Net Core System.NullReferenceException 中的 Api、ASP.NET Core 连接两个表模型返回 NullReferenceException、asp.net – ExecuteScalar抛出NullReferenceException、asp.net – MVC DropDownListFor – NullReferenceException被usercode取消了的相关知识,请在本站进行查询。
本文标签: