Submit data from Dialog to controller - asp.net-mvc

I have a View from which a button call a dialog Bootstrap.
Inside this dialog I render this view:
#using (Ajax.BeginForm("Create", new { #class = "form-control", id="form-create" }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "wrapperViews" }))
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(false)
<hr />
<div class="form-horizontal">
<div id="divParamType" style="display: none;"></div>
<div class="form-group">
#Html.LabelFor(x => Model.PhaseID, htmlAttributes: new { #class = "control-label col-md-1" })
<div class="col-md-3">
#Html.DropDownListFor(x => Model.PhaseID,
new SelectList(Model.Phases, "Value", "Text"), "", new { #class = "form-control", id = "Phase" })
#Html.ValidationMessageFor(x => Model.PhaseID, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(x => Model.ParamID, "Description", htmlAttributes: new { #class = "control-label col-md-1" })
<div class="col-md-3">
#Html.DropDownListFor(x => Model.ParamID,
new SelectList(Model.ProcessIDListParams, "Value", "Text"), "", new { #class = "form-control", id = "ProcessParam" })
#Html.ValidationMessageFor(x => Model.ParamID, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group" id="forList">
#Html.LabelFor(x => Model.CodeValue, htmlAttributes: new { #class = "control-label col-md-1" })
<div class="col-md-3">
#Html.DropDownListFor(x => Model.CodeValue,
new SelectList(Model.PPvalues, "Value", "Text"), "", new { #class = "form-control", id = "PPValue" })
#Html.ValidationMessageFor(x => Model.CodeValue, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group" id="forOtherType">
#Html.LabelFor(x => Model.CodeValue, htmlAttributes: new { #class = "control-label col-md-1" })
<div class="col-md-2">
#Html.TextBoxFor(x => Model.CodeValue, new { #class = "form-control", id = "PPValTextBox" })
#Html.ValidationMessageFor(x => Model.CodeValue, "", new { #class = "text-danger" })
<div id="idTypeValue1"></div>
</div>
#Html.Label("<=", htmlAttributes: new { #class = "control-label col-md-1", id = "SecondValueLabel" })
<div class="col-md-2">
#Html.TextBoxFor(x => Model.SecondValue, new { #class = "form-control", id = "SecondValue" })
#Html.ValidationMessageFor(x => Model.SecondValue, "", new { #class = "text-danger" })
<div id="idTypeValue2"></div>
</div>
</div>
}
by calling #Html.Action("Create", "Search")
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h5 class="modal-title">Add Parameter</h5>
</div>
<div class="modal-body">
#Html.Action("Create", "Search")
<div id="myModalContent"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<input type="submit" id="bntSubmit" , name="name" class="btn btn-primary" value="Save" />
</div>
</div>
</div>
So far so good, my dialog opens and shows the view.
But when I click on Save button , my ajax request fails for I cannot pass the data even if I serialized the form. The form id is "form-create" on the View:
#using (Ajax.BeginForm("Create", new { #class = "form-control", id="form-create" }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "wrapperViews" }))
but when result from serialize() is empty.
$(document).ready(function () {
$('#bntSubmit').click(function (e) {
debugger;
e.preventDefault();
var form = $("#form-create").serialize();
debugger;
$.ajax({
type: "POST",
url: '/Search/Create',
data: form,
success: function () {
$('#myModal').modal("hide");
},
error: function () {
alert("Dynamic content load failed.");
}
});
});
});
I tried to change id form with modal id but nothing changed.
I am struggling over this for one day and no solution yet.
Any help would be appreciated.

First, make sure you include the "jquery.unobtrusive-ajax.min.js" in your layout, "Ajax.Beginform" won't work without it.
If that doesn't work, try just submit the form.
By using an "Ajax.Beginform", you should just bind :
$(function () {
$('#bntSubmit').on('click', function (e) {
e.preventDefault();
$('form-create').submit();
});
});
And use "OnSuccess" event in the "AjaxOptions" object to do the rest.

Related

remote validation does not work for partial view

I have order with several order items and I use partial view to load order items. I want to validate OrderLineItemEntity's ProductCode but it does not work. Every other property validation works which is not in partial view. How can I force to validate partial view too?
Order View:
<div id="orderLineItemsContainer" class="form-group">
#Html.EditorFor(model => model.OrderLineItems)
</div>
OrderLineItems View:
#model SalesManagementSystem.Models.OrderEntity
#Html.EditorFor(model => model.OrderLineItems)
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
OrderLineItem View:
#model SalesManagementSystem.Models.OrderLineItemEntity
<div class="form-inline col-md-12" style="margin-bottom: 5px">
<div class="form-group col-md-6">
#Html.LabelFor(model => model.ProductCode, htmlAttributes: new { #class = "control-label col-md-4" })
<div class="col-md-8">
#Html.EditorFor(model => model.ProductCode, new { htmlAttributes = new { #class = "form-control", id = "ProductCode" } })
#Html.ValidationMessageFor(model => model.ProductCode, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group col-md-6">
#Html.LabelFor(model => model.Quantity, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Quantity, new { htmlAttributes = new { #class = "form-control", id = "ProductQuantity" } })
#Html.ValidationMessageFor(model => model.Quantity, "", new { #class = "text-danger" })
</div>
</div>
#if (Model != null)
{
<a onclick="deleteRow('#Model.ProductCode')">Delete</a>
}
</div>
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
ValidationController:
public JsonResult IsProductCodeValid(int ProductCode){...}
This is how I update my order items when new item is added. I think I need to add something here.
$("#btnAdd").click(function () {
var order = {
'Id': $("#Id").val(),
'Date': $("#Date").val(),
'ConsultantId': $("#ConsultantId").val(),
'OrderLineItems': getOrderLineItems()
};
$.ajax({
url: '#Url.Action("AddOrderItem", "Orders")',
type: "POST",
data: {
order: order
},
success: function (partialView) {
$("#orderLineItemsContainer").html(partialView);
},
failure: function (response) {
alert("failed");
}
});
});
Update:
I tried adding
jQuery.validator.unobtrusive.parse("#ProductCode");
And
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
Still not working
you can add a name and id (like ProductForm) property to your partial view form
after that, in cshtml file's script section
you can add a screen control method like this
function ScreenControl() {
if ($('#ProductForm')[0].checkValidity()) {
// do what do you want
} else {
$("#btnSave2").click();
}
}
and you should add 2 buttons to bottom of the form, one of them should be hidden like
<label class="col-md-1 control-label"></label>
<div class="col-md-1">
<button class="btn btn-sm btn-primary" style="float: right" type="button" id="btnSave" name="btnSave" value="Save" onclick="ScreenControl()">
<i class="fa fa-save"></i>
Save
</button>
</div>
<button class="btn btn-sm btn-primary" type="submit" id="btnSave2" name="btnSave2" value="Save" style="display: none">
<i class="fa fa-save"></i> Save
</button>

Partial view load with layout page

When I tried to load my partial view inside the modal. it loads with layout page also. But I didn't put my layout page to my partial view. Why layout page called automatically to my partial view I cannot find the layout page called in in partial view.
This is my partial view code
#model Mvc.Models.Company
#Scripts.Render("~/bundles/jquery")
#Scripts.Render("~/bundles/jqueryval")
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Company</h4>
<hr />
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(model => model.Name, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Name, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Name, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Address, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Address, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Address, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.PhoneNumber, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.PhoneNumber, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.PhoneNumber, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.URL, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.URL, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.URL, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Email, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Email, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Email, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Active, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
<div class="checkbox">
#Html.EditorFor(model => model.Active)
#Html.ValidationMessageFor(model => model.Active, "", new { #class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Tstamp, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Tstamp, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Tstamp, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.IsDeleted, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
<div class="checkbox">
#Html.EditorFor(model => model.IsDeleted)
#Html.ValidationMessageFor(model => model.IsDeleted, "", new { #class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
#Html.ActionLink("Back to List", "Index")
</div>
This is my Controller code
public ActionResult _Create()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult _Create([Bind(Include = "CompanyID,Name,Address,PhoneNumber,URL,Email,Active")] Company company)
{
if (ModelState.IsValid)
{
db.Companies.Add(company);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(company);
}
Calling Create page from the Index page
<button id="createCompanyButton" type="button" class="btn btn-info">Create Company</button>
<div class="modal fade" role="dialog" id="createCompanyFormModal" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Default Modal</h4>
</div>
<div id="createCompanyFormModalbody" class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
</div>
<script>
$(document).ready(function() {
$(document).on('click','#createCompanyButton', function(event) {
event.preventDefault();
event.stopImmediatePropagation();
$.ajax({
url: '/Companies/_Create',
type: 'GET',
success: function(data) {
$('#createCompanyFormModalbody').html(data);
$('#createCompanyFormModal').modal('show');
},
error: function() {
alert("There is some problem in the service!");
}
});
});
});
</script>
Try returning PartialView() instead of View()
I think your problem lies in your action, you are returning partial view result.
try this, I hope this will work for you!
public ActionResult _Create()
{
return PartialView("_nameOfPartial");
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult _Create([Bind(Include = "CompanyID,Name,Address,PhoneNumber,URL,Email,Active")] Company company)
{
if (ModelState.IsValid)
{
db.Companies.Add(company);
db.SaveChanges();
return RedirectToAction("Index");
}
return PartialView("_NameOfPatial", company);
}
if you are showing partial list on your index then you should return like this
public ActionResult Index(PrintingListSearchFilter filter)
{
//your model logic
return Request.IsAjaxRequest() ? PartialView("_yourListPartialView", model) :
View("Index", model) as ActionResult;
}

Load Partial View Inside the Modal

create partial view but it's not loaded inside the modal. I tried so many ways but still no luck to load partial view inside the modal. what I tried it is in down. I want to load another action method such as create method inside the modal window.
https://www.youtube.com/watch?v=3he9CLXmASo
Above link is example i want to do like this.
This is my modal code
<script>
$(document).ready(function() {
$("#showGame").click(function() {
var url = $("#gameModal").data("url");
$.get(url, function(data) {
$("#gameContainer").html(data);
$("#gameModal").modal("show");
});
});
});
<div class="modal fade" id="gameModal" data-url="#Url.Action("Create")">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Default Modal</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
This is my Partial view code
#model Mvc.Models.Company
#using (Html.BeginForm()) {
#Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Company</h4>
<hr />
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(model => model.Name, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Name, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Name, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Address, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Address, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Address, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.PhoneNumber, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.PhoneNumber, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.PhoneNumber, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.URL, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.URL, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.URL, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Email, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Email, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Email, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Active, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
<div class="checkbox">
#Html.EditorFor(model => model.Active)
#Html.ValidationMessageFor(model => model.Active, "", new { #class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Tstamp, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.Tstamp, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Tstamp, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.IsDeleted, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
<div class="checkbox">
#Html.EditorFor(model => model.IsDeleted)
#Html.ValidationMessageFor(model => model.IsDeleted, "", new { #class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>}
<div>
#Html.ActionLink("Back to List", "Index")
</div>
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
This is my Controller Code
public ActionResult Create()
{
return View();
}
// POST: Companies/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "CompanyID,Name,Address,PhoneNumber,URL,Email,Active,Tstamp,IsDeleted")] Company company)
{
if (ModelState.IsValid)
{
db.Companies.Add(company);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(company);
}
First write your modal related html code as follows:
// Button that will trigger the modal
<button id="createCompanyButton" type="button" class="btn btn-info">Create Company</button>
// Your modal code
<div class="modal fade" role="dialog" id="createCompanyFormModal" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Default Modal</h4>
</div>
<div id="createCompanyFormModalbody" class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
</div>
Then in the JavaScript:
$(document).ready(function() {
$(document).on('click','#createCompanyButton', function(event) {
event.preventDefault();
event.stopImmediatePropagation();
$.ajax({
url: '/Companies/Create',
type: 'GET',
success: function(data) {
$('#createCompanyFormModalbody').html(data);
$('#createCompanyFormModal').modal('show');
},
error: function() {
alert("There is some problem in the service!")
}
});
});
});
Now it should show the form into modal when click the createCompanyButton button.

MVC Post Action method not firing

I am currently working on inserting records functionality of MVC 5 application. For some reason the post action method doesn't fire. I am created an button on View that should trigger the post action method. Not sure why it is not firing. The form elements are in partial view and the button control is not the main view that host the partial view.
Here is the code
Main view
#model CC.GRP.MCRequest.ViewModels.NewRequestViewModel
<div class="newrequest">
#Html.Partial("~/Views/Request/RequestHeaderView.cshtml");
</div>
<div id="buttonalign" class="buttonalign" >
<button type="button" class="btn btn-primary">Submit</button>
<button type="button" class="btn btn-default" onclick="location.href='#Url.Action("Request_Insert", "Request")'" >Save as draft</button>
</div>
Request Header View
#model CC.GRP.MCRequest.ViewModels.NewRequestViewModel
#using (Html.BeginForm())
{
<div id="NewRequest">
<div class="row">
<div class="col-md-4">
<div class="form-group">
#Html.LabelFor(model => model.RequestID, htmlAttributes: new { #class = "control-label col-md-4" })
<div class="col-md-6">
<div class="editor-field">
#Html.EditorFor(model => model.RequestID, new { htmlAttributes = new { #class = "form-control", style = "width:100%", #readonly = "readonly" } })
</div>
#Html.ValidationMessageFor(model => model.RequestID, "", new { #class = "text-danger" })
</div>
</div>
<div class="clearfix"></div>
<div class="form-group">
#Html.LabelFor(model => model.Name1, htmlAttributes: new { #class = "control-label col-md-4" })
<div class="col-md-6">
<div class="editor-field">
#(Html.Kendo().ComboBoxFor(model => model.Name1)
.HtmlAttributes(new { style = "width:100%" })
.DataTextField("Name1")
.DataValueField("CustomerMasterDataId")
.DataSource(dataSource => dataSource
.Read(read => read.Action("RequestHeader_CustomerData", "Request").Type(HttpVerbs.Post))
)
.Events(e =>
{
e.Change("onCustomerComboChange");
})
)
</div>
#Html.ValidationMessageFor(model => model.CustomerNumber, "", new { #class = "text-danger" })
</div>
</div>
<div class="clearfix"></div>
<div class="form-group">
#Html.LabelFor(model => model.CustomerNumber, htmlAttributes: new { #class = "control-label col-md-4" })
<div class="col-md-6">
<div class="editor-field">
#Html.EditorFor(model => model.CustomerNumber, new { htmlAttributes = new { #class = "form-control", style = "width:100%", #readonly = "readonly" } })
</div>
#Html.ValidationMessageFor(model => model.CustomerNumber, "", new { #class = "text-danger" })
</div>
</div>
</div>
</div>
Request Controller
[HttpPost]
public ActionResult Request_Insert(NewRequestViewModel userVM)
{
NewRequestViewModel newReqeustViewModel = new NewRequestViewModel();
if (!ModelState.IsValid)
{
return null;
}
requestRepository.CreateRequest(Mapper.Map<Request>(userVM));
//return Json(requestRepository.CreateRequest(userVM));
return View("NewRequestView", newReqeustViewModel);
}
you should put
<div id="buttonalign" class="buttonalign" >
<button type="button" class="btn btn-primary">Submit</button>
<button type="button" class="btn btn-default" onclick="location.href='#Url.Action("Request_Insert", "Request")'" >Save as draft</button>
</div>
inside
#using (Html.BeginForm("Request_Insert", "Request", FormMethod.Post))
{
}
in Request Header View
and
update
<button type="button" class="btn btn-primary">Submit</button>
to
<button type="submit" class="btn btn-primary">Submit</button>

Bootstrap form labels not placed before the textbox?

I'm not seeing why the following code is putting the labels to the right of the textbox instead of the to the left? Should I be using <div class="row"> around the <div class="form-group">?
Anyone know what I'm missing?
<div class="form-horizontal">
#using (Html.BeginForm("EditClockGroup", "Admin", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
#Html.ValidationSummary(false, "", new { #class = "alert alert-danger" })
#Html.HiddenFor(model => model.GroupId, null)
<div class="form-group">
#Html.LabelFor(m => m.GroupId, new { #class = "col-md-2 control-label" })
#Html.TextBoxFor(m => m.GroupId, new { #class = "col-md-7 form-control" })
</div>
<div class="form-group">
#Html.LabelFor(m => m.GroupName, new { #class = "col-md-2 control-label" })
#Html.TextBoxFor(m => m.GroupName, new { #class = "col-md-7 form-control" })
</div>
<div class="form-group">
<div class="col-md-7 col-md-offset-2">
<input type="submit" value="Update" class="btn btn-primary" />
</div>
</div>
}
</div>
You cannot apply col-md-7 to input tag. Instead, you need to place input inside div.
<div class="form-group">
#Html.LabelFor(m => m.GroupId, new { #class = "col-md-2 control-label" })
<div class="col-md-7">
#Html.TextBoxFor(m => m.GroupId, new { #class = "form-control" })
</div>
</div>

Resources