hi Frnds
I am doing add a new row in a web grid...but if I click on add button it is not a working
m sending to u my code also
please share the solution where I m in stuck
note//// Ifirst I want the empty web grid...if I click on add button it should be add and save it..
public int ID { get; set; }
public string Name { get; set; }
public string SurName { get; set; }
public static List
{
List
{
};
@{
var grid = new WebGrid(Model);
}
@grid.GetHtml(
tableStyle: "webgrid-table",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
selectedRowStyle: "webgrid-selected-row",
rowStyle: "webgrid-row-style",
mode: WebGridPagerModes.All,
columns:
grid.Columns(
grid.Column("ID", format: @
grid.Column("Name", "Name", format: @
grid.Column("SurName", "Sur Name", format: @
grid.Column("Action", format: @
))
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Anjali KhanPosted Aug 25, 2016, 4:17 AM
Hi Frnds
I am sending to u my code ...but i am stuck in if i click on add button new row is not be add on the web grid in mvc4
please chek the code and give the solution
Model////
public class UserModel
{
public int ID { get; set; }
public string Name { get; set; }
public string LastName { get; set; }
//public static List getUsers() users = new List(); getUsers() users = new List()
//{
// List
// {
// new UserModel();
// /*{ ID = 1, Name = "Anubhav", SurName = "Chaudhary" }; */
// };
// users.Add(new UserModel());
// //{ ID = 1, Name = "Anubhav", SurName = "Chaudhary" });
// return (users);
//}
public static List
{
List
{
new UserModel (){ ID=4, Name="Jyoti", LastName="Mishra" },
new UserModel (){ ID=5, Name="Shayli", LastName="Shamra" },
};
return users;
}
}
Views////
@{
ViewBag.Title = "Index";
}
WEB GRID
@{
var grid = new WebGrid(Model);
}
@grid.GetHtml(
columns:
, style: "col1Width"),
, style: "col2Width"),
, style: "col2Width"),
grid.Columns(
grid.Column("ID", format: @
@item.ID
grid.Column("Name", "Name", format: @
grid.Column("LastName", "LastName", format: @
)
))
@*Add button for adding the textbox*@
Controller/////
public ActionResult Index() users = UserModel.getUsers();
{
List
return View(users);
}
Vinay SinghPosted Aug 24, 2016, 7:07 AM