I have 2 actions in my controller, Create and Edit, that essentially uses the same view, as the function of adding and editing a record is the same.
So in my view, I have this:
@using (Html.BeginForm("Create", "Customers", FormMethod.Post, new { @class = "form-horizontal" }))
I could just use @using (Html.BeginForm()) { }
But that way, I don’t see any overload method to add in my css class files
How do I use the same BeginForm helper for both my Create and Edit actions without having to hard code it?
Or what other ways, or best practices should be employed if I want to set a style to my form tag, which will be used for 2 different actions.
I’ve done the same thing as you, with one view for both actions. In the controller, I just pass a ViewBag property, called Action which is set dependeding on the context. In the view, just call @Html.BeginForm(ViewBag.Action, …).