0

A beginner's dilemma . Shows error in firebug for the values of mobile and country code. My script File

$(function () { $('#edit-form').submit(function () { member = { FirstName: $('#f-name').val(), Middlename: $('#m-name').val(), LastName: $('#l-name').val(), CountryCode: $('#mobcc-name').val(), Mobile: $('#mob-name').val(), Languages: $('#Language').val(), Email: $('#email-name').val() }; if ($('#edit-form input').length = 0) { $('#message').html('<strong>Error : </strong><span style="color: #e2442b;">Please fill the required fields</span>'); return; } else { $('#message').html('<strong>Processing : </strong><span>Saving information. Please wait...</span>'); } $('#edit-form .wrap').children('*:not(label)').attr('disabled', true); $.ajax({ url: "/Account/Edit", type: 'POST', data: member, success: function (d) { if(d.s){ $('#message').html('<strong>Success : </strong><span class="success_msg">Your information saved</span>'); setTimeout(function () { $('#message').children().fadeOut(); }, 5000); } else { $('#message').html('<strong>Error : </strong><span class="error_msg">' + d.m + '</span>'); } $('#data .ip_wrap').children('*:not(label)').attr('disabled', false); }, error: function () { $('#message').html('<strong>Error : </strong><span style="class="error_msg"">A server error occured. Please try after some time. Inconvenience regretted</span>'); $('#edit-form .wrap').children('*:not(label)').attr('disabled', false); } }); }); $('#cancel').click(function () { if (document.referrer != '') { history.back(); } else { location.href = "/Account/Index"; } }); }); 

My View File (Form)

@model Just.In.Models.User @{ ViewBag.Title = "Edit User"; } @section head{<link href="~/Content/Style/Account/Edit.css" rel="stylesheet" /> <script src="~/Content/Scripts/Account/edit.js"></script>} <div class="wrapper"> <div class="content"> <div class ="top-banner"> <p class="pageTitle">Edit @Model.FullName Profile</p> </div> <p class="helpText"><i>Make changes to the profile</i></p> <form id ="edit-form" action ="javascript:void(0)"> <section class="group"> <p class= "u-name wrap"><label class ="lbl">User Name</label><input id="u-name" class="input" type="text" value="@Model.UserName" disabled/></p> <p class="f-list wrap"><label class ="lbl">First Name</label><input id="f-name" class="input" type="text" value="@Model.FirstName" /></p> <p class="m-list wrap"><label class ="lbl">Middle Name</label><input id="m-name" class="input" type="text" value="@Model.Middlename" /></p> <p class="l-list wrap "><label class ="lbl">Last Name</label><input id="l-name" class="input" type="text" value="@Model.LastName" /></p> <p class="mob-list wrap"><label class ="lbl">Mobile Number</label><input id="mobcc-name" class="input" type="text" value="@Model.CountryCode" /> <input id="mob-name" class="input wrap" type="text" value="@Model.Mobile" /></p> <p class="lan-name wrap "><label class="lbl">Language</label><span class ="input">@Html.DropDownListFor(o => o.Language, (IEnumerable<SelectListItem>)ViewBag.Languages)</span></p> <p class="e-list wrap"><label class ="lbl">e-mail</label><input id="email-name" class="input" type="text" value="@Model.Email" /></p> </section> <p class="wrap snd-form"><input id="send" class="sbt" type="submit" value="Save" /><input id="cancel" class="sbt" type="button" value="Cancel" /></p> </form> <div class ="message"></div> <div class="error-list" hidden> <h2 class="pageTitle">Access Denied</h2> <p class="helpText">You don't have enough permission to edit this profile.</p> </div> </div> </div> 

and my Controller , I'm not sure whether this is right or not!!!

public JsonResult Edit(string FirstName, string Middlename, string LastName, short CountryCode, int Mobile, Language Languages, string Email) { Models.User users = new User { FirstName = FirstName, Middlename = Middlename, LastName = LastName, CountryCode = CountryCode, Mobile = Mobile, Language = Languages,Email =Email }; if (users.Save()) { return Json(new { s = users.Status == UserStatus.Active, m = "Not changed", id = users.UserID }); } else return Json(new {s = false, m = "You don't have enough permission to edit this profile" }); } 

and My method for Save

 public bool Save() { bool updated = false; DatabaseCommaned cmd = new DatabaseCommaned(); cmd.CommandText = "UPDATE tUser SET"; if (_firstName != FirstName) { cmd.CommandText += " FNAID = @fnaid,"; cmd.Parameters.AddWithValue("@fnaid", string.IsNullOrEmpty(FirstName) ? DBNull.Value : (object)Names.GetName(FirstName).NameID); updated = true; } if (_middleName != Middlename) { cmd.CommandText += " MNAID = @mnaid,"; cmd.Parameters.AddWithValue("@mnaid", string.IsNullOrEmpty(Middlename) ? DBNull.Value : (object)Names.GetName(Middlename).NameID); updated = true; } if (_lastName != LastName) { cmd.CommandText += " LNAID = @lnaid,"; cmd.Parameters.AddWithValue("@lnaid", string.IsNullOrEmpty(LastName) ? DBNull.Value : (object)Names.GetName(LastName).NameID); updated = true; } if (_email != Email) { cmd.CommandText += " Email = @email,"; cmd.Parameters.AddWithValue("@email", Email); updated = true; } if (_countryCode != CountryCode) { cmd.CommandText += "MobCountryCode = @ccode, "; cmd.Parameters.AddWithValue("@ccode", CountryCode); updated = true; } if (_mobile != Mobile) { cmd.CommandText += " Mobile = @mob,"; cmd.Parameters.AddWithValue("@mob", Mobile); updated = true; } if (_status != Status) { cmd.CommandText += " ST = @st,"; cmd.Parameters.AddWithValue("@st", Status); updated = true; } if (_language != Language) { cmd.CommandText += " LN = @ln,"; cmd.Parameters.AddWithValue("@ln", Language); updated = true; } if (_expiry != Expiry) { cmd.CommandText += " ExpDT = @exp,"; cmd.Parameters.AddWithValue("@exp", Expiry); updated = true; } if (updated == true) { cmd.CommandText = cmd.CommandText.TrimEnd(','); cmd.CommandText += " WHERE UID = @uid"; cmd.Parameters.AddWithValue("@uid", _userID); updated = cmd.ExecuteNonQuery() == 1; if (updated) { copyPropertiesInternally(); Logs.LogEvent(LogEvent.UserUpdated, _userNA); } } return updated; } 

The error in FireBug

Server Error in '/' Application. The parameters dictionary contains a null entry for parameter 'Mobile' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.JsonResult Edit(System.String, System.String, System.String, Int16, Int32, PASKAN.Web.Security.Models.Language, System.String)' in 'PASKAN.Web.Security.Controllers.AccountController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters 
2
  • 2
    Can you copy paste the error or provide the link to it by pasting it online?
    – iamkhush
    CommentedJun 24, 2013 at 7:07
  • and it also shows Use of attributes' specified attribute is deprecated. It always returns true. [Break On This Error] return !val || val.specified ? elem.value : elem.text; jquery-1.9.1.js (line 2270)
    – JRU
    CommentedJun 24, 2013 at 7:20

1 Answer 1

1

'Mobile' property is not nullable int so you should check for it in the client because it passed to the server as null

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.