I post last time but I think my question is wrong. So I figured it out. Currently, I am working on a project right now I'm 75% of the project I get stacked in the edit view I just want to pass 2 or multiple models in a view I do view model but it needs to iterate before you call the properties of that class or the model. I've done that but I don't know how to pass a model in a dropdownlistfor().
I want to achieve a edit view below of that I need table and in the table it has a dropdownlistfor() list of bedroom1, bedroom2, bedroom3 and so on..
Code:
public async Task<ActionResult> Edit(long? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var vm = await _context.DwPropertyMasters.FindAsync(id);
if (vm == null)
{
return HttpNotFound();
}
TempData["MapPointX"] = vm.MapPointX;
TempData["MapPointY"] = vm.MapPointY;
var vmMapPoint = new MapPointEditViewModels
{
LandId = vm.LandId,
Location = vm.Location,
AreaSize = vm.AreaSize,
AreaSize2 = vm.AreaSize2,
Mgm = vm.Mgm,
Developer = vm.Developer,
MapPointX = vm.MapPointX,
MapPointY = vm.MapPointY,
ShowMapPoint = vm.ShowMapPoint,
BatchUpdate = vm.BatchUpdate,
Development = vm.Development,
Premium = vm.Premium,
LandLot = vm.LandLot,
LastModifiedBy = vm.LastModifiedBy,
LandTypeId = vm.LandTypeId,
LandTypes = _context.DwPropertyLandTypes.ToList(),
YearTender = vm.YearTender,
DownloadLinkRt1 = vm.DownloadLinkRt1,
DownloadLinkRt2 = vm.DownloadLinkRt2,
};
var vmDetails = _context.DwPropertyDetails.Where(y => y.LandId == id)
.Select(y => new
{
y.Block,
y.Floor,
y.Unit,
y.SalePrice,
y.TransactionPrice,
y.ActualSize,
y.FlatType
}).ToList();
ViewData["Details"] = vmDetails.Select(x => new DwPropertyDetail
{
Block = x.Block,
Floor = x.Floor,
Unit = x.Unit,
SalePrice = x.SalePrice,
TransactionPrice = x.TransactionPrice,
ActualSize = x.ActualSize,
FlatType = x.FlatType
});
return View(vmMapPoint);
}
View:
<div class="form-group">
<table class="table table-bordered table-hover" style="font-size: smaller; text-align: center; width: 100%;" id="detailsDataTable">
<thead style="background: #ecf0f1; color: #7f8c8d;">
<tr class="cls-property">
<th>No.</th>
<th>Block</th>
<th>Floor</th>
<th>Unit</th>
<th>Transaction Price</th>
<th>Sale Price</th>
<th>Size</th>
<th>Flat Type</th>
</tr>
</thead>
<tbody>
@{ var counter = 0;}
@foreach (var details in (IEnumerable<DwPropertyDetail>)ViewData["Details"])
{
<tr>
<td>@(++counter)</td>
<td>@Html.DisplayFor(model => details.Block)</td>
<td>@Html.DisplayFor(model => details.Floor)</td>
<td>@Html.DisplayFor(model => details.Unit)</td>
<td>@Html.DisplayFor(model => details.TransactionPrice)</td>
<td>@Html.DisplayFor(model => details.SalePrice)</td>
<td>@Html.DisplayFor(model => details.ActualSize)</td>
<td>@Html.EditorFor(model => details.FlatType, new { htmlAttributes = new { @class = "form-control input-sm" } })</td>
</tr>
}
</tbody>
</table>
</div>