public class UserDetails1
{
public int UserId { get; set; }
public string UserName { get; set; }
public string Education { get; set; }
public string Location { get; set; }
public List<userdetails1> usersinfo { get; set; }
}
My controller code as follows (Controller Name as User1)
[HttpPost]
public ActionResult Details(UserDetails1 user)
{
UserDetails1 objuser = new UserDetails1();
using (SqlConnection con = new SqlConnection("Data Source=Trenmax;Integrated Security=true;Initial Catalog=Sample"))
{
using (SqlCommand cmd = new SqlCommand("usercrudoperations", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@name", user.UserName);
cmd.Parameters.AddWithValue("@education", user.Education);
cmd.Parameters.AddWithValue("@location", user.Location);
cmd.Parameters.AddWithValue("@status", "INSERT");
con.Open();
ViewData["result"] = cmd.ExecuteNonQuery();
con.Close();
}
}
return View();
}
My views code as follows (View name as Details)
@model InsertGetUserDetails1.Models.UserDetails1
@{
ViewBag.Title = "Details";
}
<h2>Details</h2>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Details</title>
<script src="~/Scripts/jquery-1.10.2.js"></script>
</head>
<body>
@using (Html.BeginForm("Details","User1",FormMethod.Post)) {
<table>
<tr>
<td>User Name:</td>
<td>@Html.TextBoxFor(u=>u.UserName)</td>
</tr>
<tr>
<td>Education:</td>
<td>@Html.TextBoxFor(u => u.Education)</td>
</tr>
<tr>
<td>Location:</td>
<td>@Html.TextBoxFor(u=>u.Location)</td>
</tr>
<tr>
<td></td>
<td> <input type="submit" value="Register" /> </td>
</tr>
</table>
}
<h4>User Details</h4>
@if (Model != null)
{
if (Model.usersinfo.Count > 0)
{
<table>
<tr>
<th>UserId</th>
<th>UserName</th>
<th>Education</th>
<th>Location</th>
</tr>
@foreach (var item in Model.usersinfo)
{
<tr>
<td>@Html.DisplayFor(modelitem => item.UserId) </td>
<td>@Html.DisplayFor(modelitem => item.UserName)</td>
<td>@Html.DisplayFor(modelitem => item.Education)</td>
<td>@Html.DisplayFor(modelitem => item.Location)</td>
</tr>
}
</table>
}
else {
<b>No Details Found.</b>
}
}
<script type="text/javascript">
$(function () {
var msg = '@ViewData["result"]';
if (msg == '1')
{
alert("User Details Inserted Successfully");
window.location.href = "@Url.Action("InsertUserDetails", "User")";
}
});
</script>
</body>
</html>
When i run the above code http://localhost:5129/User1/Details Note: User1 - ControllerName
Details - ViewName
shows error as follows
Server Error in '/' Application.
The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: /User1/Details what is the mistake in my above code