I work on asp.net MVC application . I get error input string not in correct format
i don’t know what is the reason of this issue and which line give me this issue
on local pc issue not happen but on iis publish site web app it happen
so how i know reason of this issue please
and can i do some enhancement on code to display more clear message or prevent this error from happen
And which line generate issue
if i write some parsing on code with wrong way please tell me to correct it
my action code as below
public class ResignationRequester
{
[Display(Name = "Employee No : ")] [Required,]
public int EmpID { get; set; }
[Display(Name = "Line Manager: ")]
public int? LineManager { get; set; }
}
[HttpPost]
public JsonResult RequesterIndex(ResignationRequester resignationRequester)
{
dynamic responseData = new ExpandoObject();
responseData.success = false;
responseData.message = "";
try
{
var filenumber = resignationRequester.EmpID;
if (Session[SessionKeys.UserCode] != null)
{
JDEUtility jde = new JDEUtility();
resignationRequester.EmpID = Convert.ToInt32(Session[SessionKeys.UserCode]);
if (ModelState.IsValid)
{
if (Convert.ToString(resignationRequester.LineManager).Length < 6 && !string.IsNullOrEmpty(resignationRequester.LineManager.ToString()))
{
responseData.success = false;
responseData.message = "Length Line Manager Must Be equal 6 or More";
return Json(responseData);
}
if (Convert.ToInt32(resignationRequester.EmpID) == Convert.ToInt32(resignationRequester.DirectManager) &&
Convert.ToInt32(resignationRequester.EmpID) == Convert.ToInt32(resignationRequester.LineManager)
&& !string.IsNullOrEmpty(Convert.ToString(resignationRequester.LineManager)) && !string.IsNullOrEmpty(Convert.ToString(resignationRequester.DirectManager)))
{
responseData.success = false;
responseData.message = "Requester Have Same Number of Manager";
return Json(responseData);
}
if (!string.IsNullOrEmpty(Convert.ToString(resignationRequester.LineManager)))
{
responseData.success = false;
responseData.message = "Line Manager Name Blank";
return Json(responseData);
}
if (string.IsNullOrEmpty(ViewBag.errorMsg))
{
responseData.success = true;
responseData.message = "Resignation Submission form Created successfully";
return Json(responseData);
}
}
}
}
catch (System.FormatException ex)
{
responseData.success = false;
responseData.message = ex.Message;
}
return Json(responseData);
}
on UI View this is what i do
$("#txtLineManagerId").autocomplete({
source: function (request, response) {
var searchText = $("#txtLineManagerId").val();
console.log("search text" + searchText)
$.ajax({
url: '@Url.Action("GetAllEmployeeBasedSearchText", "Resignation")',
data: { searchText: searchText },
method: "GET",
dataType: "json",
success: function (data) {
if (!data.length) {
var result = [
{
label: 'No matches found',
value: response.term
}
];
response(result);
}
else {
response($.map(data, function (item) {
return {
label: "File No : " + item.EmployeeID + " - " + "Name :" + item.EmployeeName + " - " +
"Designation : " + item.Designation, value: item.EmployeeID,
employeeName: item.EmployeeName,
designation: item.Designation
};
}))
}
}
});
},
position: { my: "right top", at: "right bottom" },
appendTo: '#searchContainer',
select: function (event, ui) {
$("#LineManagerName").val(ui.item.employeeName);
},
minLength: 2,
}).data("ui-autocomplete")._renderItem = function (ul, item) {
console.log("after autocomplete" + item);
return $("<li>")
.append("<div>File No: " + item.value + "<br/>Name: " + item.employeeName + "<br/>Designation: " + item.designation + "</div>")
.appendTo(ul);
};
<div class="form-group col-md-6">
<div class="col-md-5">
@Html.LabelFor(model => model.LineManager, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-7">
@Html.EditorFor(model => model.LineManager, new
{
htmlAttributes = new
{
@class = "form-control"
,
id = "txtLineManagerId"
}
})
<div id="searchContainer">
</div>
</div>
</div>
You need to learn how to debug your code to find which line is actually causing the error. Having said that, what is
SessionKeys.UserCode
? What happens if that is null, or an empty string? Same question forresignationRequester.DirectManager
thanks for support session.usercode represent session that i logged with it and i assign for EmpId because i will insert Empid value on table and i check it not null resignationRequester.DirectManager is integer value and it is not null