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 trying to add values to dictionary. Here is my code :-

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

Controller

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

An exception of type

System.NullReferenceException

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] http://i.stack.imgur.com/eL8HQ.png

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();
    dr.Read();

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

    dr.Close();

    con.Close();
}

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);

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

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

response.redirect("main.aspx")

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

pic

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.

This question already has an answer here:

Well i have this in the PostController:

public ActionResult Index()
{
 List<Post> Posts = PostLogic.GetPosts(db);
 return View(Posts);
}

public ActionResult User()
{
 List<Post> Posts = PostLogic.GetPosts(db);
 return View(Posts);
}   

Index and User are doing the same things, the problem is that i'm getting System.NullReferenceException from User. Here is my working Index view:

@model IEnumerable<ProjectX.Models.Post>
 @foreach (var item in Model)
 {
 @item.post
 }

Here is my non working User view:

 @model IEnumerable<ProjectX.Models.Post>

    @foreach (var item in Model)
    {
    @item.post
    }

Why am i getting NullReferenceException from the Userview when the indexview works perfect?

This question already has an answer here:

Hi I am new to MVC I am trying to disable a button if a few textboxfor fields are not entered or are null. I have tried the following code below but no luck, I get an object null error.

@if (String.IsNullOrEmpty(modelData.Email))
{
    <input type="submit" class="btn btn-default" value="Register" onclick="JavascriptFunction()" disabled="disabled" />
}
else
{
    <input type="submit" class="btn btn-default" value="Register" onclick="JavascriptFunction()" />
}

HTML Text box definition

@Html.TextBoxFor(m => m.Email, new { @placeholder = "example: dlamini@gmail.com", @class = "form-control", id = "message", onkeypress = "capLock(event)" })

This happens when the Registration.cshtml page loads, please assist.

This question already has an answer here:

I've noticed that one of my ASP.NET MVC apps started generating a NullReferenceException error when a custom error message is added to the model state. When that happens, I end up getting an error on one of the Html.TextBoxFor calls the view uses. The controller looks like this:

public async Task<ActionResult> ConfirmPayment(PaymentInfo model){
  try{
    //this will generate an exception
    PaymentManager.Pay(...);
  }
  catch(PaymentException ex){
   _logger.Error(ex);
   var field = MapErrorToField(ex); //this returns the name of one of the fields
   ModelState.AddModelError(field, "error");
  }

I've found some links that suggested the problem could be solved by calling SetModelValue. Unfortunately, that did not solve my problem.

Any help?