I have a view that was generated using data scaffolding. The view has a textfield:
Create View:
You could do this by using the ViewBag
to store GroupId
as you currently are, but as your view is using a model, it may be better to go that way instead.
So you would have:
Model:
public class GroupModel
{
public int GroupId { get; set; }
}
Controller:
public ActionResult Create(int id)
{
var model = new GroupModel();
model.GroupId = id
return View(model);
}
At the top of your view, you would then reference your model:
@model GroupModel
You can then access the model in the view using code like model.GroupId
as per the scaffolding has done.