I work on asp.net mvc web application . i face issue on RequesterIndex action with type Post when call it by ajax request it give me
message Invalid File No although I assigned value of session user code to Employee Id when click submit button action Requester
index with type post fire then it give me message Invalid File No why this message display for me . I assign value of session user code
to employee id also i store employee id on hidden field to avoid reset when submit my link use to access requester index action on resignation controller
so Why message Invalid File No display when click submit button this is my question . my code for action and view related to issue as below :
public class ResignationController : Controller
{
public class ResignationRequester
{
[Display(Name = "Employee No : ")] [Required,]
public int EmpID { get; set; }
}
//get method
public ActionResult RequesterIndex(string filenumber)
{
int employeeFileNo;
if (!string.IsNullOrEmpty(filenumber))
{
if (int.TryParse(filenumber, out employeeFileNo))
{
Session[SessionKeys.UserCode] = employeeFileNo;
resignationRequester.EmpID = Convert.ToInt32(Session[SessionKeys.UserCode].ToString());
Session[SessionKeys.UserCode] = employeeFileNo;
}
}
else
{
ViewBag.errorMsg = "unauthorized user";
}
return View(resignationRequester);
}
//post method
public JsonResult RequesterIndex(ResignationRequester resignationRequester)
{
dynamic responseData = new ExpandoObject();
responseData.success = false;
responseData.message = "";
try
{
var filenumber = resignationRequester.EmpID;
if (Session[SessionKeys.UserCode] != null)
{
if (int.TryParse(Session[SessionKeys.UserCode].ToString(), out int empId))
{
resignationRequester.EmpID = empId;
}
else
{
responseData.success = false;
responseData.message = "Invalid File No";
return Json(responseData);
}
}
else
{
responseData.success = false;
responseData.message = "No Data For This File No";
return Json(responseData);
}
}
catch (System.FormatException ex)
{
responseData.success = false;
responseData.message = ex.Message;
}
return Json(responseData);
}
}
requesterIndex.cshtml
Resignation Form
Jignesh KumarPosted Jan 30, 2024, 9:48 AM
Hello,
Are you getting value on registration post request for empId?
ahmed salahPosted Jan 30, 2024, 5:29 AM
can you please show me by code how to assign value of employee id using hidden field instead of using session
i using jquery ajax request because i don't need form url chaged after submit
so can you help me please to assign hidden field to employee id instead using session user code
Jignesh KumarPosted Jan 30, 2024, 3:57 AM
Hello Ahemad,
Have you check your get method executed every time before your post method call ?
It seems your session is not assigned before your post call. please try to attach debugger and check your session is getting assigned properly or not ?