I want to display a partial view inside a main view upon clicking view link, within the same page. Help me please, I am newbie in MVC. Is there any other way to do it other than using the Ajax.ActionLink()?
This is my Add Detail controller.
public ActionResult DisplayDetails()
{
SqlConnection connect = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
connect.Open();
DataSet ds = ExecuteQuery("select EmployeeID, EmployeeName, EmailID from EmployeeDetails");
IList<AddDetails> lst = new List<AddDetails>();
AddDetails ad;
foreach (DataRow dr in ds.Tables[0].Rows)
{
ad = new AddDetails();
ad.EmployeeId = Convert.ToInt32(dr["EmployeeID"]);
ad.EmployeeName = dr["EmployeeName"].ToString();
ad.EmailId = dr["EmailID"].ToString();
lst.Add(ad);
}
connect.Close();
return PartialView("DisplayDetails", lst);
}
Here is the main view AddDetail view(main view).
@model mvcEmployeeTask.Models.AddDetails
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
@using (Html.BeginForm("AddDetail", "AddDetails", FormMethod.Post))
{
<table>
@* <tr>
<td>
@(Html.Label("Employee ID : "))
</td>
<td>
@Html.TextBoxFor(model => model.EmployeeId)
@Html.HiddenFor(model => model.EmployeeId)
</td>
</tr>*@
@Html.HiddenFor(model => model.EmployeeId)
<tr>
<td>
@(Html.Label("Employee Name : "))
</td>
<td>
@(Html.TextBoxFor(model => model.EmployeeName))
</td>
</tr>
<tr>
<td>
@(Html.Label("Email ID : "))
</td>
<td>
@(Html.TextBoxFor(model => model.EmailId))
</td>
</tr>
<tr>
<td>
<input type="submit" value="submit" name="Add" />
</td>
<td>
@* @Html.ActionLink("View", "DisplayDetails")*@
@Html.ActionLink("View", "DisplayDetails")
</td>
</tr>
</table>
@Html.Action("DisplayDetails", "AddDetails");
}
Here is the partial view (Display view).
@model IList<mvcEmployeeTask.Models.AddDetails>
@{
Layout = null;
}
@using (Html.BeginForm("DisplayDetails", "AddDetails", FormMethod.Get))
{
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>DisplayDetails</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
</head>
<body> <div class="table" align="center">
<table border="1" >
<tr>
<th>EmployeeID</th>
<th>EmployeeName</th>
<th>Email</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@item.EmployeeId
</td>
<td>
@item.EmployeeName
</td>
<td>
@item.EmailId
</td>
<td>
@Html.ActionLink("Edit", "EditDetails", new { id= item.EmployeeId })
</td>
<td>
@Html.ActionLink("Delete", "DeleteDetails", new { id= item.EmployeeId })
</td>
</tr>
}
</table>
</div>
</body>
</html>
}
Please Help me!!