Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In my application I am having Html table grid. The HTMl table grid is available in the partialview, in that grid I am having 5 rows with the dropdownselection to change the Groupmembers. The save button is available in the Main view. When the user changes the Groupmembers and click on save button I want to save the records into the database. How to get the records of the partialview HTML table grid records and how to save it. And also I want to know, if the records is available in database it should get Update else it should insert. Below is my code:

Index.cshtml:

@model DM_Tool_MVC_Site.ViewModels.GroupHeadViewModels
@{
ViewBag.Title = "Group Heads";
}
<script type="text/javascript">
$(document).ready(function () {
var DivisId = $('#SelectedDivision option:selected').val();
if (DivisId == 0) {
$("#btnEdit").hide();
$("#btnUpdate").hide();
}
else {
$("#btnEdit").show();
}
//$("#btnEdit").hide();
//$("#btnUpdate").hide();
//$('#GroupList').hide();
$('#SelectedDivision').change(function () {
var DivId = $('#SelectedDivision option:selected').val();
if (DivId == 0) {
$("#btnEdit").hide();
$("#btnUpdate").hide();
}
else
{
$("#btnEdit").show();
$("#btnUpdate").hide();
}
$.get('@Url.Action("GroupHeadIndexPartial")',
{ DivisionID: DivId,EditMode:false }, function (data) {
//$('#GroupList').show();
$("#GroupList").html(data);
});
});
});
</script>

User Management


@using (Html.BeginForm("Index", "GroupHead", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()

@ViewBag.Title





@Html.LabelFor(m => m.SelectedDivision, new { @class = "col-md-2 control-label" })

@Html.DropDownListFor(m => m.SelectedDivision, Model.GetDivision().Select(u => new SelectListItem
{
Text = u.Text,
Value = u.Value,
Selected = u.Text == ViewBag.CurrentSelection as string
}), "--Choose Division--", new { @class = "form-control" })



<input type="submit" name="Edit" value="Edit" class="btn btn-default" id="btnEdit" />


@Html.Action("GroupHeadIndexPartial", new { DivisionID = ViewBag.CurrentSelection as string, EditMode = ViewBag.EditMode as string })



@if (Model.IsEditMode == false)
{
<input type="submit" name="Update" class="btn btn-default" value="Update" id="btnUpdate" disabled="disabled" />
}
else
{
<input type="submit" name="Update" class="btn btn-default" value="Update" id="btnUpdate" />
}

}

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}



GroupIndexPartialView.cshtml:

@model IEnumerable<dm_tool_mvc_site.viewmodels.groupheadlist>


@foreach (var item in Model)
{
}

Group
Group Head
@Html.DisplayFor(modelItem => item.GroupName)
@Html.HiddenFor(modelItem => item.DivID)
@Html.HiddenFor(modelItem => item.GroupId)
@Html.DropDownListFor(modelItem => item.GroupHeadUserName, item.UsersSelectList(item.DivID,item.GroupId).Select(u => new SelectListItem
{
Text = u.Text,
Value = u.Value,
Selected = u.Text == item.GroupHeadUserName
}), "--Select Group Head--", item.EditMode ? (object)new { @class = "form-control" } : new { @readonly = "readonly", @class = "form-control" })

@*@Html.DisplayFor(modelItem => item.GroupHeadUserName)*@

Thanks
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900