First the parameter expected by the action, must cause routing problems, because is configured by default for HttpGet request. But when you do a submit of html form, the parameters send to the server is serialized different.
You should try this way:
[HttpGet]
public ActionResult EditData(int id)
{
try
{
using (SqlConnection con = new SqlConnection(connStr))
{
string sql_cmd = "select UserId,UserName,FirstName,LastName from UserDetails where UserId=@id";
SqlCommand cmd = new SqlCommand(sql_cmd, con);
cmd.Parameters["@id"].Value = id;
}
}
catch (Exception)
{
}
return View();
}
and view is
@using (Html.BeginForm(FormMethod.Get))
{
@grid.GetHtml(tableStyle:"webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: grid.Columns(
grid.Column("LastName","Last Name",format:@
@item.last_name
),
grid.Column("View Details", header: "Edit", format: @
@Html.ActionLink("Edit","EditData","UserInfo", new {id=item.user_id}, null)
),grid.Column("Delete", header: "Delete", format: @
@Html.ActionLink("Delete",null,null, new { username = item.user_id }, null)
)))
}
More help:
https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters%28v=vs.110%29.aspx[
^]
http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/asp-net-mvc-routing-overview-cs[
^]