I got a question.
I'm making a table but I need a add page where the user can fill in a textbox, (or something else) Then press add. If this happens the table needs to be updated with the information the user added.
Could some one help me? Because I do not know how to start.
The code from the table page:
#model IEnumerable<DNDB.Models.Domeinnaam>
#Styles.Render("~/Content/StyleSheet.css")
#{
ViewBag.Title = "Index";
}
<h2>Domeinnaam Overzicht</h2>
#Html.ActionLink("add", "CreateDomeinnaam.cshtml")
<table id="tabledomeinnamen">
<tr>
<th>
#Html.DisplayNameFor(model => model.IsActief)
</th>
<th>
#Html.DisplayNameFor(model => model.Naam)
</th>
<th>
#Html.DisplayNameFor(model => model.TLD)
</th>
<th>
#Html.DisplayNameFor(model => model.DatumRegistratie)
</th>
<th>
#Html.DisplayNameFor(model => model.Omschrijving)
</th>
<th>
#Html.DisplayNameFor(model => model.DatumOpzeg)
</th>
<th>
#Html.DisplayNameFor(model => model.EigenaarID)
</th>
<th>
#Html.DisplayNameFor(model => model.Opmerking)
</th>
<th>
#Html.DisplayNameFor(model => model.BeheerAccountID)
</th>
<th>
#Html.DisplayNameFor(model => model.KlantID)
</th>
<th>
#Html.DisplayNameFor(model => model.RegistrarID)
</th>
<th>
#Html.DisplayNameFor(model => model.BetaaldVan)
</th>
<th>
#Html.DisplayNameFor(model => model.BetaaldTot)
</th>
<th>
#Html.DisplayNameFor(model => model.AfspraakPrijs)
</th>
<th></th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.IsActief)
</td>
<td>
#Html.DisplayFor(modelItem => item.Naam)
</td>
<td>
#Html.DisplayFor(modelItem => item.TLD)
</td>
<td>
#Html.DisplayFor(modelItem => item.DatumRegistratie)
</td>
<td>
#Html.DisplayFor(modelItem => item.Omschrijving)
</td>
<td>
#Html.DisplayFor(modelItem => item.DatumOpzeg)
</td>
<td>
#Html.DisplayFor(modelItem => item.EigenaarID)
</td>
<td>
#Html.DisplayFor(modelItem => item.Opmerking)
</td>
<td>
#Html.DisplayFor(modelItem => item.BeheerAccountID)
</td>
<td>
#Html.DisplayFor(modelItem => item.KlantID)
</td>
<td>
#Html.DisplayFor(modelItem => item.RegistrarID)
</td>
<td>
#Html.DisplayFor(modelItem => item.BetaaldVan)
</td>
<td>
#Html.DisplayFor(modelItem => item.BetaaldTot)
</td>
<td>
#Html.DisplayFor(modelItem => item.AfspraakPrijs)
</td>
<td>
#Html.ActionLink("Edit", "Edit", new { id=item.ID })
#Html.ActionLink("Details", "Details", new { id=item.ID })
#Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
</table>
The code from the table page:
#Html.ActionLink("add", "CreateDomainName", "Domain") //Second parameter is the action name, Third parameter is the controller name. If your 'list'(table) page action and 'add' action are in the same controller then this field is optional.
CreateDomainName action in your controller.
public ActionResult CreateDomainName()
{
return View();
}
[HttpPost]
public ActionResult CreateDomainName(Domeinnaam model)
{
if(ModelState.IsValid)
{
//Your code to save
}
return RedirectToAction("Index");
}
To generate the view of CreateDomainName action, right click on action and click on 'add view'.
View of CreateDomainName action.
#using(Html.BeginForm())
{
<!-- Your html code -->
<input type="submit">Add</input>
}
You can perform this task in two ways:
Using Ajax
By submitting form to server and refreshing the page
Here's how you can do it via ajax.
Add form at top or bottom of table with required fields
On submit of form event process form and submit via ajax
In success callback append tr to table with required cells.
$( document ).ready(function() {
$("#newForm").submit(function(){
//TODO: Perform ajax call to add reccord in database
// Append row to table
return false;
});
Here's a code demo you can follow to do it with Ajax. Add new row to table on form submit
Related
My goal is to allow users to print to pdf, a view. I found a Nuget called Rotativa and followed some very basic tutorials. In test, it worked perfectly and looked like a great answer to meet my needs.
However, I am finding that implementing it into the actual working project, is giving me errors that the simple test did not.
I have an index view that is a list. I want users to print this list to pdf. I have tried many different classes of Rotativa (ViewAsPDF, ActionAsPDF, GeneratePDF. . . ). I have researched and read numerous tutorials . .but I think the problem is more related to my Model. .
Here is what I have so far
Index View
#model IEnumerable<ICS20web.Models.IndexViewModel>
#{
ViewBag.Title = "Index";
}
<style>
#content {
}
.even {
background-color: #dcf1b8;
}
.odd {
background-color: #f4ffe1;
}
</style>
<h2>Index</h2>
<p>
#Html.ActionLink("Create New", "Create")
</p>
<p>
<p>
#Html.ActionLink("Print", "PrintAllReport")
</p>
<table class="table">
<tr>
<th>
#Html.DisplayNameFor(model => model.ItemDescription)
</th>
<th>
#Html.DisplayNameFor(model => model.OriginalDate)
</th>
<th>
#Html.DisplayNameFor(model => model.TransType)
</th>
<th>
#Html.DisplayNameFor(model => model.LastUpdatedBy)
</th>
<th>
#Html.DisplayNameFor(model => model.ContactName)
</th>
<th>
#Html.DisplayNameFor(model => model.OpenClosed)
</th>
<th>
#Html.DisplayNameFor(model => model.CurrentStatus)
</th>
<th>
#Html.DisplayNameFor(model => model.CurrentStatusDate)
</th>
<th>
#Html.DisplayNameFor(model => model.RequsitionNumber)
</th>
<th>
#Html.DisplayNameFor(model => model.PONumber)
</th>
<th>
#Html.DisplayNameFor(model => model.DeliveryMonth)
</th>
<th>
#Html.DisplayNameFor(model => model.DeliveryYear)
</th>
<th>
#Html.DisplayNameFor(model => model.UnitsOrdered)
</th>
<th>
#Html.DisplayNameFor(model => model.Emergency)
</th>
<th>
#Html.DisplayNameFor(model => model.Comments)
</th>
<th>
#Html.DisplayNameFor(model => model.DeliveryUnit)
</th>
<th></th>
</tr>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.ItemDescription)
</td>
<td>
#Html.DisplayFor(modelItem => item.OriginalDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.TransType)
</td>
<td>
#Html.DisplayFor(modelItem => item.LastUpdatedBy)
</td>
<td>
#Html.DisplayFor(modelItem => item.ContactName)
</td>
<td>
#Html.DisplayFor(modelItem => item.OpenClosed)
</td>
<td>
#Html.DisplayFor(modelItem => item.CurrentStatus)
</td>
<td>
#Html.DisplayFor(modelItem => item.CurrentStatusDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.RequsitionNumber)
</td>
<td>
#Html.DisplayFor(modelItem => item.PONumber)
</td>
<td>
#Html.DisplayFor(modelItem => item.DeliveryMonth)
</td>
<td>
#Html.DisplayFor(modelItem => item.DeliveryYear)
</td>
<td>
#Html.DisplayFor(modelItem => item.UnitsOrdered)
</td>
<td>
#Html.DisplayFor(modelItem => item.Emergency)
</td>
<td>
#Html.DisplayFor(modelItem => item.Comments)
</td>
<td>
#Html.DisplayFor(modelItem => item.DeliveryUnit)
</td>
<td>
#Html.ActionLink("Edit", "Edit", new { id = item.TransID })
</td>
</tr>
}
</table>
The View loads in the browser, with correct data from the model, properly. But, when the user clicks the ActionLink PrintAllReport . . . I see the following error: System.NullReferenceException: Object reference not set to an instance of an object.
Referencing line #foreach (var item in Model)
I believe that is telling me that the Model is empty? But, how can that be, when it populates in the browser just fine.
Here is My Index Controller Action
public ActionResult Index()
{
var q = from tr in db.ICS_Transactions
join un in db.ICS_Units
on tr.DeliveryUnitID equals un.DeliveryUnitID
join kt in db.ICS_Contacts
on tr.Contact equals kt.LoginID
join sp in db.ICS_Supplies on tr.SuppliesID equals sp.Supplies_ID
orderby tr.Emergency descending, tr.TransID ascending
select new IndexViewModel
{
TransID = tr.TransID,
ItemDescription = sp.ItemDescription,
OriginalDate = tr.OriginalDate,
TransType = tr.TransType,
LastUpdatedBy = tr.LastUpdatedBy,
ContactName = kt.ContactName,
OpenClosed = tr.OpenClosed,
CurrentStatus = tr.CurrentStatus,
CurrentStatusDate = tr.CurrentStatusDate,
RequsitionNumber = tr.RequsitionNumber,
PONumber = tr.PONumber,
DeliveryMonth = tr.DeliveryMonth,
DeliveryYear = tr.DeliveryYear,
UnitsOrdered = tr.UnitsOrdered,
Emergency = tr.Emergency,
Comments = tr.Comments,
DeliveryUnit = un.DeliveryUnit,
PhoneNumber = un.PhoneNumber,
Street = un.Street,
City = un.City,
State = un.State,
ZipCode = un.ZipCode,
Building = un.Building,
Room = un.Room
}
;
return View(q.Where(d => d.OpenClosed == "Open").ToList());
}
And here is my PrintAllReport Action
public ActionResult PrintAllReport()
{
var model = new IndexViewModel();
//Code to get content
return new Rotativa.ViewAsPdf("Index") { FileName = "TestViewAsPdf.pdf" };
}
This generates the Object Reference Error. I am confused. Shouldn't this work exactly as the index loaded in the browser? What am I missing?
I have also tried it this way:
public ActionResult PrintAllReport()
{
var report = new ActionAsPdf("Index");
return report;
}
The latter gives me an authentication error: You are not authorized to view this page due to invalid authentication headers.
I am new to MVC5 and I am confused as to why the index page loads properly, but the action PrintAllReport is failing to open in pdf. And what I need to change to make it work properly.
Update:
After Stuard gave me some good information, I have made some changes, as follows
{
var viewModel = new IndexViewModel();
var report = new ViewAsPdf("Index", viewModel);
return report;
}
Now, I am getting a different error
The model item passed into the dictionary is of type 'ICS20web.Models.IndexViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[ICS20web.Models.IndexViewModel]'
I feel like I am close . . . but no cigar.
I have a view which has a table that displays values. I would like to add a drop down that filters the results of the status column. So for example if I select "Reviewing", only records with the "Reviewing" status will appear. Below I have my view.
#model IEnumerable<DRT.Models.Master>
#{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
#Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
#Html.DisplayNameFor(model => model.RequestType.Name)
</th>
<th>
#Html.DisplayNameFor(model => model.Reviewer.Name)
</th>
<th>
#Html.DisplayNameFor(model => model.Status.Name)
</th>
<th>
#Html.DisplayNameFor(model => model.ProjectName)
</th>
<th>
#Html.DisplayNameFor(model => model.ProjectLocation)
</th>
<th>
#Html.DisplayNameFor(model => model.Requestor)
</th>
<th>
#Html.DisplayNameFor(model => model.DateReceived)
</th>
<th>
#Html.DisplayNameFor(model => model.ReviewCompDate)
</th>
<th>
#Html.DisplayNameFor(model => model.ProjectFolerLink)
</th>
<th>
#Html.DisplayNameFor(model => model.ModellingReferralDate)
</th>
<th>
#Html.DisplayNameFor(model => model.ModellingReviewCompletionDate)
</th>
<th>
#Html.DisplayNameFor(model => model.SewerMaintenanceReferralDate)
</th>
<th>
#Html.DisplayNameFor(model => model.SewerMaintenanceReviewCompletionDate)
</th>
<th>
#Html.DisplayNameFor(model => model.FlowControlReferralDate)
</th>
<th></th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.RequestType.Name)
</td>
<td>
#Html.DisplayFor(modelItem => item.Reviewer.Name)
</td>
<td>
#Html.DisplayFor(modelItem => item.Status.Name)
</td>
<td>
#Html.DisplayFor(modelItem => item.ProjectName)
</td>
<td>
#Html.DisplayFor(modelItem => item.ProjectLocation)
</td>
<td>
#Html.DisplayFor(modelItem => item.Requestor)
</td>
<td>
#Html.DisplayFor(modelItem => item.DateReceived)
</td>
<td>
#Html.DisplayFor(modelItem => item.ReviewCompDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.ProjectFolerLink)
</td>
<td>
#Html.DisplayFor(modelItem => item.ProjectComments)
</td>
<td>
#Html.DisplayFor(modelItem => item.DischargeLocationID)
</td>
<td>
#Html.DisplayFor(modelItem => item.DischargeDistrict)
</td>
<td>
#Html.DisplayFor(modelItem => item.SystemType)
</td>
<td>
#Html.DisplayFor(modelItem => item.AffectedRequlator)
</td>
<td>
#Html.DisplayFor(modelItem => item.StartDateOfDischarge)
</td>
<td>
#Html.DisplayFor(modelItem => item.DurationOfDischarge)
</td>
<td>
#Html.DisplayFor(modelItem => item.RequestFlowRate)
</td>
<td>
#Html.DisplayFor(modelItem => item.ApprovedDischargeRate)
</td>
<td>
#Html.DisplayFor(modelItem => item.DischargeLocationComments)
</td>
<td>
#Html.DisplayFor(modelItem => item.ModellingReferralDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.ModellingReviewCompletionDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.SewerMaintenanceReferralDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.SewerMaintenanceReviewCompletionDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.FlowControlReferralDate)
</td>
<td>
#Html.ActionLink("Edit", "Edit", new { id=item.MasterId }) |
#Html.ActionLink("Details", "Details", new { id=item.MasterId }) |
#Html.ActionLink("Delete", "Delete", new { id=item.MasterId })
</td>
</tr>
}
</table>
You basically need a SELECT element in your view and when use selects something, you may post the selected value to the action method where you will use this value when getting data from your db.
You may create a new view model
public class ListAndSearchVm
{
public IEnumerable<DRT.Models.Master> Data { set;get;}
public IEnumerable<SelectListItem> Statuses { set;get;}
public string SelectedStatus { set;get;}
}
Now in your GET action, you need to load the Statuses property of the view model and the Data property. Have a parameter to accept the selected option value from your status filter dropdown. Based on the value of this parameter get the filtered data.
public ActionResult Index(string selectedStatus="")
{
var vm= new ListAndSearchVm();
//Hard coding 2 items for demo. You can read this from your db table
vm.Statuses = new List<SelectListItem> {
new SelectListITem { Value="Open", Text="Open"},
new SelectListITem { Value="Closed", Text="Closed"},
};
var data= dbContext.Masters;
if(!String.IsNullOrEmpty(selectedStatus))
{
data = data.Where(f=>f.Status.Name==selectedSatatus);
}
vm.Data = data.ToList();
return View(vm);
}
Now in your view
#model ListAndSerchVm
#using(Html.BeginForm("Index","YourControllerName",FormMethod.Get))
{
<label> Select a status</label>
#Html.DropDownListFor(f=>f.SelectedStatus,Model.Statuses,"Select")
<input type="submit" value="Filter" />
}
<table>
<tr>
<th>Request type</th>
<th>Reviewer</th>
<th>Status</th>
</tr>
#foreach(var item in Model.Data)
{
<tr>
<td>#item.RequestType.Name)</td>
<td>#item.Reviewer.Name</td>
<td>#item.Status.Name</td>
</tr>
}
</table>
So I am building a report to be displayed on our website, I created a view for the qry and dropping it into our .EDMX file. I can set up the view for the site with that query however the data in the database is not matching up with what is being shown on screen. The dates are what is messing up, everything else matches. Any thoughts as to what is wrong?
SELECT TOP 1000 [Name]
,[Manufacturer]
,[SerialNumber]
,[TSIFBarcode]
,[NextCalibrationDate]
,[Description]
,[CalibrationCost]
,[Location]
,[RoutineInspection]
,[Comment]
,[Priority]
FROM [InsertDBHere]
That is my sql code, below is my code to create the view from my controller:
IEnumerable<qryCalibrationEquipmentTracker> view = db.qryCalibrationEquipmentTrackers;
view = view.OrderBy(a => a.NextCalibrationDate);
return View(view);
Below is code for the view
#model IEnumerable<MvcDBFirst.Models.qryCalibrationEquipmentTracker>
#{
ViewBag.Title = "Calibration Tracking Report";
}
<h2>Calibration Tracking Report</h2>
#if (ViewBag.PrintMode == null || !ViewBag.PrintMode)
{
<div class="float-right clear-fix">
<div class="amMenu">
<ul class="amMenuLinksHoriz clear-fix">
<li>
<a href="#Url.Action("ExportCalTracking", "Reports")">
<img src="#Url.Content("~/images/assetmgr/printer.png")" height="25px" alt="Printer" />
</a>
</li>
<li>
#*<a href="#Url.Action("ExcelCalTracking", "Reports")">*#
<a onclick="postTableData('amCalIndexTable')">
<img src="#Url.Content("~/images/assetmgr/excel.png")" height="25px" alt="Excel" />
</a>
</li>
</ul>
</div>
</div>
}
<h2>Report Run on #DateTime.Now.ToString()</h2>
<table class="amCalIndexTable">
<thead>
<tr>
<th>
#Html.DisplayNameFor(model => model.Name)
</th>
<th>
#Html.DisplayNameFor(model => model.Manufacturer)
</th>
<th>
#Html.DisplayNameFor(model => model.SerialNumber)
</th>
<th>
#Html.DisplayNameFor(model => model.TSIFBarcode)
</th>
<th>
#Html.DisplayNameFor(model => model.NextCalibrationDate)
</th>
<th>
#Html.DisplayNameFor(model => model.Priority)
</th>
<th>
#Html.DisplayNameFor(model => model.Description)
</th>
<th>
#Html.DisplayNameFor(model => model.CalibrationCost)
</th>
<th>
#Html.DisplayNameFor(model => model.Location)
</th>
<th>
#Html.DisplayNameFor(model => model.RoutineInspection)
</th>
<th>
#Html.DisplayNameFor(model => model.Comment)
</th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.Name)
</td>
<td>
#Html.DisplayFor(modelItem => item.Manufacturer)
</td>
<td>
#Html.DisplayFor(modelItem => item.SerialNumber)
</td>
<td>
#Html.DisplayFor(modelItem => item.TSIFBarcode)
</td>
<td>
#Html.DisplayFor(modelItem => item.NextCalibrationDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.Priority)
</td>
<td>
#Html.DisplayFor(modelItem => item.Description)
#*Html.ActionLink(item.Description, "Details", "tblItems",
new
{
type = item.fkItemType,
serialNumber = item.SerialNumber,
owner = item.fkOwner
}, null
)*#
</td>
<td>
#Html.DisplayFor(modelItem => item.CalibrationCost)
</td>
<td>
#Html.DisplayFor(modelItem => item.Location)
</td>
<td>
#Html.DisplayFor(modelItem => item.RoutineInspection)
</td>
<td>
#Html.DisplayFor(modelItem => item.Comment)
</td>
</tr>
}
</tbody>
Convert your view to List before the OrderBy like this. view.ToList().OrderBy().
Like this.
IEnumerable<qryCalibrationEquipmentTracker> view = db.qryCalibrationEquipmentTrackers;
view = view.ToList().OrderBy(a => a.NextCalibrationDate);
return View(view);
This was a Microsoft issue, since it was a query it didnt have a primary key. Microsoft came in and randomly chose a primary key. We have updated our query to deal with this.
So, I am new to MVC, and I have a partial view with IEnumerable model, in which I have few fields I would like to be editable.
#model IEnumerable<Allocations>
<p>
#Html.ActionLink("Create New", "AddAllocation", "Admin")
</p>
<table class="table">
<tr>
<th>
#Html.DisplayNameFor(model => model.Name)
</th>
<th>
#Html.DisplayNameFor(model => model.Description)
</th>
<th>
#Html.DisplayNameFor(model => model.Percentage)
</th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.Name)
</td>
<td>
#Html.DisplayFor(modelItem => item.Description)
</td>
<td>
#Html.EditorFor(modelItem => item.Percentage)
</td>
<td>#Html.HiddenFor(modelItem => item.ID)</td>
<td>
#Html.ActionLink("Save", "EditAllocation", "Admin", null, new { id= item.ID })
</td>
</tr>
}
</table>
I want to be able to pass the entered/changed textbox values to the controller action. I understand, I can do that using JQuery if it wasn't a IEnumerable model view. I might be missing something here, and would appreciate if someone could direct me in the right direction.
In my MVC5 Application, I am currently dealing with 2 tables:
[MemberDues] -- [Id], [Year], [Display], [Amount]
[MemberDuesReceived] -- [Id], [MemberDuesId], [MemberOrgId], [PaidByUserId], [TransactionId], [Paid], [DatePaid], [PaymentMethod], [PayPalPaymentId], [PayPalPayerId], [PayPalPaymentState]
I have a View (below) where I display the records for Different [MemberDues]:
#model IEnumerable<PROJECTdev.Models.MemberDues>
<script type="text/javascript" src="~/Areas/Admin/Scripts/Dues/Index.min.js"></script>
<div id="alert" style="display: none;"></div>
<table class="table table-striped">
<thead>
<tr>
<th class="col-md-2">
</th>
<th>
#Html.DisplayNameFor(model => model.Year)
</th>
<th>
#Html.DisplayNameFor(model => model.Display)
</th>
<th>
#Html.DisplayNameFor(model => model.Amount)
</th>
<th>View</th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td>
<span class="glyphicon glyphicon-pencil"></span> Edit
<span class="glyphicon glyphicon-floppy-remove"></span> Delete
</td>
<td>
#Html.DisplayFor(modelItem => item.Year)
</td>
<td>
#Html.EditorFor(modelItem => item.Display, new { htmlAttributes = new { #class = "form-control pull-left", style = "height: 20px; width: 20px;", onclick = "disableEnableDues(" + item.Id + ", this)" } })
</td>
<td>
#Html.DisplayFor(modelItem => item.Amount)
</td>
<td>
<span class="glyphicon glyphicon-list-alt"></span> Paid
</td>
</tr>
}
</tbody>
</table>
What I am attempting to do is have, when the [Paid] button (link) is clicked, a View is brought up which lists all the Member Organizations which have paid their dues. To do this, I have to query [MemberDuesReceived] for the appropriate [MemberDuesId] and return all records which have the matching [MemberDuesId] & [Paid] == true. This I have attempted to below:
public async Task<ActionResult> DuesPaidMembers(int id)
{
MemberDues memberDues = await db.MemberDues.FindAsync(id);
return View(db.MemberDuesReceived.Where(mdr => mdr.MemberDuesId == memberDues.Id && mdr.Paid).ToListAsync());
}
I then created a view called DuesPaidMembers.cshtml which is below:
#model IEnumerable<PROJECTdev.Models.MemberDuesReceived>
#{
ViewBag.Title = "DuesPaidMembers";
Layout = "~/Areas/Admin/Views/Shared/_LayoutAdmin.cshtml";
}
<h2>DuesPaidMembers</h2>
<p>
#Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
#Html.DisplayNameFor(model => model.MemberDues.Id)
</th>
<th>
#Html.DisplayNameFor(model => model.MemberOrganization.Name)
</th>
<th>
#Html.DisplayNameFor(model => model.PaidByUser.Name)
</th>
<th>
#Html.DisplayNameFor(model => model.TransactionId)
</th>
<th>
#Html.DisplayNameFor(model => model.Paid)
</th>
<th>
#Html.DisplayNameFor(model => model.DatePaid)
</th>
<th>
#Html.DisplayNameFor(model => model.PaymentMethod)
</th>
<th>
#Html.DisplayNameFor(model => model.PayPalPaymentId)
</th>
<th>
#Html.DisplayNameFor(model => model.PayPalPayerId)
</th>
<th>
#Html.DisplayNameFor(model => model.PayPalPaymentState)
</th>
<th></th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.MemberDues.Id)
</td>
<td>
#Html.DisplayFor(modelItem => item.MemberOrganization.Name)
</td>
<td>
#Html.DisplayFor(modelItem => item.PaidByUser.Name)
</td>
<td>
#Html.DisplayFor(modelItem => item.TransactionId)
</td>
<td>
#Html.DisplayFor(modelItem => item.Paid)
</td>
<td>
#Html.DisplayFor(modelItem => item.DatePaid)
</td>
<td>
#Html.DisplayFor(modelItem => item.PaymentMethod)
</td>
<td>
#Html.DisplayFor(modelItem => item.PayPalPaymentId)
</td>
<td>
#Html.DisplayFor(modelItem => item.PayPalPayerId)
</td>
<td>
#Html.DisplayFor(modelItem => item.PayPalPaymentState)
</td>
<td>
#Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
#Html.ActionLink("Details", "Details", new { id=item.Id }) |
#Html.ActionLink("Delete", "Delete", new { id=item.Id })
</td>
</tr>
}
</table>
Currently however, when I click the button, my appropriate Controller Action (DuesPaidMember()) is called, but when the line return View(db.MemberDuesReceived.Where(mdr => mdr.MemberDuesId == memberDues.Id && mdr.Paid).ToListAsync()); is hit, I receive the following error:
The model item passed into the dictionary is of type 'System.Threading.Tasks.Task1[System.Collections.Generic.List1[PRISMdev.Models.MemberDuesReceived]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[PRISMdev.Models.MemberDuesReceived]'.`
Does anyone have any thoughts on what I'm apparently doing wrong?
The following line is to blame.
return View(db.MemberDuesReceived
.Where(mdr => mdr.MemberDuesId == memberDues.Id && mdr.Paid)
.ToListAsync());
You are passing the result of ToListAsync as your model, which is a Task<List<PRISMdev.Models.MemberDuesReceived>>.
Instead, insert await so that the task is run and the resulting value of type List<PRISMdev.Models.MemberDuesReceived> is returned as your model:
return View(await db.MemberDuesReceived
.Where(mdr => mdr.MemberDuesId == memberDues.Id && mdr.Paid)
.ToListAsync());