Sagar Bandkar

Sagar Bandkar

  • 1.4k
  • 347
  • 48.8k

View ListBoxFor healper data from Grid in MVC

Dec 24 2016 2:31 AM
I want to view data in listbox after click on view  button in Grid.other value got except ListBox value, 
 
 View:-
<div class="form-group col-xs-6 col-sm-6">
@Html.ListBoxFor(x => x.SelectedNames, Model.Names, new { Size = 20, style = "width:190%;" })
</div>
 
<div class="form-group col-xs-6 col-sm-6">
@Html.ListBoxFor(model => model.SelectedNames, new MultiSelectList("",Model.SelectedNames), new { Size = 20, style = "width:190%;" })
</div>
Controller:-
public ShiftNameViewModel ViewPatternById(int inPtnId)
{
try
{
if (inPtnId > 0)
{
tblMstPattern_PTN PatternDetail = db.tblMstPattern_PTN.Find(inPtnId);
tblTxnPatternData_PTD_T txnPatternDetail = db.tblTxnPatternData_PTD_T.Find(inPtnId);
var patternValue = new ShiftNameViewModel()
{
inPtnId = PatternDetail.inPtnId,
vcPtnCode = PatternDetail.vcPtnCode,
vcPtnName = PatternDetail.vcPtnName,
SelectedNames = PatternDetail.vcPtnData.Split(new char[] { ',' }).ToList()
};
return patternValue;
}
}
catch (Exception ex) { ex.Message.ToString(); }
return null;
}
 
 
 
In viewModel :
 
public IEnumerable<SelectListItem> Names { get; set; }
public IEnumerable<string> SelectedNames { get; set; }
 

Answers (2)