How to get maximum value of 'max id' from database in Asp.Net MVC?
Sample Reference Code:
In Controller:
- public ActionResult getClientId()
- {
- ClientMaster objCliMas = new ClientMaster();
- DataSet ds = new DataSet();
- string sQuery = " SELECT ISNULL(MAX(ClientId), 0)+1 'MaxClientId' FROM PMS_ClientMaster ";
- SqlDataAdapter da = new SqlDataAdapter(sQuery, con);
- con.Open();
- da.Fill(ds);
- con.Close();
- if (ds.Tables[0].Rows.Count > 0)
- {
- objCliMas.Id = Convert.ToInt32(ds.Tables[0].Rows[0]["MaxClientId"].ToString());
- }
- return View(objCliMas);
- }
In View:
- @Html.EditorFor(model => model.Id, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.Id, "", new { @class = "text-danger" })
At here in the view it's not displaying the maxid value.
If there's any solution please let me know it.