Hello,
I am trying to lookup an employee by their ID using a jQuery modal. My Modal has an input text box for the employee ID and a Search button. Once the search button is clicked I have the value looked up in a db and if no result exists I am looking for an error message to display on that same modal.
My controller looks like this:
[AcceptVerbs(HttpVerbs.Post)]
[ActionName("CreateEmpLookup")]
public ActionResult CreateEmpLookupPost(string empIDSearch)
{
List<spGetEmployeeDataByEIDResult> res = new List<spGetEmployeeDataByEIDResult>(_service.GetUserFromDB(empIDSearch));
if (res.Count > 0)
{
ViewData["Status"] = true;
return RedirectToAction("Create", new { empID = empIDSearch });
}
else
{
ViewData["Status"] = "false";
return Content("False");
}
}
I'm just not sure how to relay the information back to the pop up modal that there is no result. I'm thinking I have to replace this line return Content("False");
with the message that will go back to the jQuery pop up modal.
In my pop up modal I have the following line that will display any error messages:
<input type="hidden" id="Status" value="<%= (ViewData["Status"] == null) ? "true" : ViewData["Status"].ToString() %>" />
Here is a snippet of my jQuery code:
$('#login_form').modal();
And the div that jQuery targets:
<div id="login_form" style='display: none'>
<div id="status" align="left">
<center>
<h1>
<img src="../../Content/modal_images/Search48.png" alt="Key" id="modal_img" />
<label id="modal_title">
Employee Search</label>
</h1>
<br class="modal_br" />
<div id="login_response">
<input type="hidden" id="Status" value="<%= (ViewData["Status"] == null) ? "true" : ViewData["Status"].ToString() %>" />
</div>
</center>
<% using (Html.BeginForm("CreateEmpLookup", "", FormMethod.Post))
{ %>
<form id="login" action="javascript:alert('success!');">
<%--<input type="hidden" name="action" value="user_login" />
<input type="hidden" name="module" value="login" />--%>
<table class="modal_table">
<tr>
<td>
<label id="modal_label">
Employee ID:</label>
</td>
<td>
<%= Html.TextBox("empIDSearch", "", new { @maxlength = "6" })%>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input value="Search" name="Search" id="submit" type="submit" />
<div id="ajax_loading">
<img src="../../Content/modal_images/spinner.gif" alt="Processing" /> Processing...
</div>
</td>
</tr>
</table>
</form>
<% } %>
</div>
</div>
Any advice on how to make this easier or fix this problem would really help.
Thank you.