This question already has an answer here:

I am trying to avoid using Html.CheckBoxFor in MVC 5 because of the extra hidden input that is added into the DOM. Reason being i am using a template and the extra input kills the lovely css'd checkbox styling.

when doing this:

<input type="checkbox" 
id="@Html.IdFor(m => m.RememberMe)" 
name="@Html.NameFor(m => m.RememberMe)" 
value="true" checked="@(Model.RememberMe ? " checked" : String.Empty)" />

This question already has an answer here:

I am at a loss here, here is my code in my Model

 public class Movie
        public int Id { get; set; }
        public string Name { get; set; }


here is the code in my controller

public class MoviesController : Controller

        public ActionResult Random()
            var movie = new Movie();
            movie.Name = "Kevin";
            return View();

here is the code in my view

@model Vidly.Models.Movie
    ViewBag.Title = "Random";
    Layout = "~/Views/Shared/_Layout.cshtml";


Please help guys, I have no idea what I am doing wrong?

I have a _Layout file that contains this. The _HeaderModel class gets initialized correctly.

<partial name="_Header" model='new _HeaderModel((int?)ViewData["ActiveIndex"])' />

_Header contains

@model Project.Pages.Shared._HeaderModel

I get this error:

'Model' threw an exception of type 'System.NullReferenceException'

Model isn't even a null reference; trying to access the property throws this exception. I really can't do it any more basic. What am I doing wrong?

Edit: This has nothing to do with the generic NullReferenceException thread. I know what a NullReferenceException is (duh) but why would it be happening here? This is a very specific case that regards ASP.NET Core 2.

This question already has an answer here:

I am trying to add values to dictionary. Here is my code :-

public class EmpModel
    public Dictionary<String, String> EmpColumns { get; set; }


EmpModel model = new EmpModel();
model.EmpColumns.Add("one", "1"); // It gives error here

An exception of type


Why i am getting this error? How to solve this?

This question already has an answer here:

i am getting a strange error in a Web applicaton mvc project, in razor view i am getting NullReferenceException even object is not null.

here is link of screenshot of error. [screenshot of error]

Things those i already tried:

  1. Cleaned/Rebuild solution and project.
  2. Deleted Temporary ASP.NET Files.
  3. Deleted View, Renamed View.
  4. Deleted Obj folder.
  5. Changed build config to Debug/Release.

None of these helped.

Please help me to solve this.

This question already has an answer here:

creating a login form however when comparing the username and password in database to allow access am ending up with this error.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

at this line,

SqlCommand cmd3 = new SqlCommand("Select id,Username,
                                  Password from User_data 
                                  where Username='"+UserName.Text.Trim()+"'",con);

below is my code,

protected void button1_click(Object sender, EventArgs e)
    SqlCommand cmd3 = new SqlCommand("Select id,Username,Password from User_data where Username='"+UserName.Text.Trim()+"'",con);

    dr = cmd3.ExecuteReader();

    string id = dr[0].ToString();
    string un=dr[1].ToString();
    string pwd= dr[2].ToString();



This question already has an answer here:

I am using ExecuteScalar(). So It will return single column.

If the record is exist, It's not showing any error. If record is not found. It throws System.NullReferenceException on the following line

cmd.CommandText = "select top 1 UserID from [HQWebMatajer].[dbo].[SecurityUserDetails] where [UserID]=@UserID and [ReportName]='TotalSales';";
cmd.Parameters.AddWithValue("@UserID", ddlSecurityUser.SelectedValue);

string dataExist = null;
dataExist= cmd.ExecuteScalar().ToString(); // Error

This question already has an answer here:

I am seeing an intermittent issue that we cannot reliably reproduce in ASP.NET Identity (MVC 5.2.3).

The top of the stack trace suggests the issue is occurring on retrieving the password hash from the database:

System.NullReferenceException: Object reference not set to an instance of an object.
    at Portal.Web.Identity.IdentityStorageContext.<>c.<get_PasswordHash>b__6_0()
    at System.Threading.Tasks.Task`1.InnerInvoke()
    at System.Threading.Tasks.Task.Execute()

SQL server isn't logging any errors. Trying the action again succeeds. We have noticed it occuring on both live and pre-prod.

IdentityStorageContext.cs extract:

public Task<string> PasswordHash
     get { return Task<string>.Factory.StartNew(() => identityUser.PasswordHash); }

Any ideas?

This question already has an answer here:

Line 19:     
static BalloonShopConnectionString1()

Line 20:  

Line 21:
         dbConnectionString = ConfigurationManager.ConnectionStrings["BalloonShopConnection"].ConnectionString;

Line 22:
         dbProviderName = ConfigurationManager.ConnectionStrings["BalloonShopConnection"].ProviderName;

Line 23:         productsPerPage = System.Int32.Parse(ConfigurationManager.AppSettings["ProductsPerPage"]);

Line 21 Error

This question already has an answer here:

I keep getting this errro while running my web site after registration


protected void CheckFriendshipStatus() { if (Object.Equals(Session["UserId"].ToString(), Session["CurrentProfileId"].ToString())) {


This question already has an answer here:

 public static string GetHRPaidTimeOffConnectionString()
         return ConfigurationManager.ConnectionStrings[HRPAIDTIMEOFF_CONNSTRING_KEY].ConnectionString;

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.