Hi guys. Kindly show me how to capture data between two dates (BeginDate and
EndDate)on IEnumerable View model. I wanted to use modal form but its not working. The IEnumerable View model is shown below. Kindly demonstrate how I can implement this functionality from this View model below under the
From your problem i think you need to use view model for Passing list which will populate You table and also the model for you both dates. You need to create a View Model class
public class YourClassViewModel
{
public IEnumerable<YourClass> ListYourClass {get; set;}
public yourClass yourClass {get;set;}
}
try to add something like below in you view
@model Brokerage.Model.YourViewModel
@html.TextBoxFor(x => x.yourClass.StartDate) //For Start Date Text Box
<br>
@html.TextBoxFor(x => x.yourClass.EndDate) //For End Date text Box.
You can use this form code into a partial view also.
@foreach(var data in Model.listYourClass)
{
//Populate your table data here
}
Now you can receive data from of start Date and End date from View.
Thanks emrulkayes21 for your quick response. Sorry I did not attach the Model. Kindly find the model below. What I intend doing is when the
[Payment Extraction] button is clicked. It should display a modal form with Date:
FROM:[ ] TO; [ ] waiting for user input. Please add the modal view to the main view above as I find it difficult to add please. My modal view placed below the main view and the Modal Class are pasted
below. The Modal views underlines the PaymentExtractionDTO. model in red.
I observed that the @model IEnumerable<Brokerage.Model.ClientPaymentViewModel> declaration on top of the main view is not allowing the Modal view to access the PaymentExtractionDTO.The
error message is :
Error 5 'System.Collections.Generic.IEnumerable<Brokerage.Model.ClientPaymentViewModel>' does not contain a definition for 'PaymentExtractionDTO' and no extension method 'PaymentExtractionDTO' accepting a first argument of type
'System.Collections.Generic.IEnumerable<Brokerage.Model.ClientPaymentViewModel>' could be found (are you missing a using directive or an assembly reference?)
What i'm I doing wrongly please? Thanks a million in anticipation of your assistance.
public class ClientPaymentViewModel
{
public IList<Account_PremiumPayment> Account_PremiumPayment{ get; set; }
public PaymentExtractionDTO PaymentExtractionDTO { get; set; }
Yes you can not use @model IEnumerable<Brokerage.Model.ClientPaymentViewModel> because your view has Mixed Content like in one page you want to Show a list and also create a Form. But when you Strongly Typed The View with IEnumerable<Model>
then the view will not be allow you to add Strongly Typed for that Model.
I think you are almost near to the Solution. Keep your Modal inside the same view and use the below code for your view
At first Create a Model for your policy attributes
public class PolicyDetails
{
[Display(Name = "Policy Ref_Code")]
public string PolicyRefCode { get; set; }
[Display(Name = "Receipt №")]
public string ReceiptCode { get; set; }
[Display(Name = "DebitNote №")]
public string DebitNoteNo { get; set; }
[Display(Name = "Date")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? TransDate { get; set; }
public string Client { get; set; }
public string TellerNo {get; set;}
[Display(Name = "Premium Amount")]
public decimal? PremiumAmount { get; set; }
[Display(Name = "Net Premium Due")]
public decimal NetPremium { get; set; }
[Display(Name = "Policy Description")]
public string ShortDescription { get; set; }
}
Then make an User Defined Property of PolicyDeatils in your ClientPaymentViewModel like below
public class ClientPaymentViewModel
{
public IList<Account_PremiumPayment> Account_PremiumPayment{ get; set; }
public PaymentExtractionDTO PaymentExtractionDTO { get; set; }
public IEnumerable<PolicyDetails> PolicyDetailsList { get; set;}
}
Not populate the Exact list for PolicyDetails in you Controller which will somethings like below
public ActionResult YourActionName()
{
ClientPaymentModel model = new ClientPaymentModel();
model.PolicyDetailsList = //retrive your list
return View(model)
}
Now receive the data in your controller like below
[HttpPost]
Public ActionResult SubmitData(ClientPaymentViewModel model)
{
var startdate = model.PaymentExtractionDTO.StartDate;
var endDate = model.PaymentExtractionDTO.EndDate
//Enjoy with Start Date and End Date
}
I quite appreciate your assistance, however, its not working as the PaymentExtractionDTO still shows errors on the modal. You mentioned Partial View in your first reply. How do I get it done using Partial View please.
Cam you send me your Model, Controller and View File ??? Or paste here the full code in 3 sections 1. Model , 2. Controller, 3. View so that i can try to find what is the exact problem. An also Attach a screen shot of your Error.
Thank you. I have reconfigured the Model as shown below with Explanations. The data to be retrieved are contained inside
Account_ClientReceiptDistribution. First I used IEnumerable to List the full content of the file into a view
[ListPremiumPayment] with the intention to using Modal on it to retrieve the Transactions that falls into the
[BeginDate] and [EndDate] for payment. These dates were pass as arguments [DateTime beginDate, DateTime endDate] into the [HttpGet]
to retrieve the transactions that falls within the Date range, which will then Generate the Payment.
1. Model
public class ClientPaymentViewModel
{
public IList<Account_ClientReceiptDistribution> Account_ClientReceiptDistribution { get; set; }
public IList<Underwriting_InvoicePaid> Underwriting_InvoicePaid { get; set; }
[Display(Name = "FROM:")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime BeginDate { get; set; }
[Display(Name = "TO:")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime EndDate { get; set; }
[Display(Name = "Policy Ref_Code")]
public string PolicyRefCode { get; set; }
[Display(Name = "Receipt №")]
public string ReceiptCode { get; set; }
[Display(Name = "DebitNote №")]
public string DebitNoteNo { get; set; }
[Display(Name = "Date")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? TransDate { get; set; }
public string Client { get; set; }
public string TellerNo {get; set;}
[Display(Name = "Premium Amount")]
public decimal? PremiumAmount { get; set; }
[Display(Name = "Net Premium Due")]
public decimal NetPremium { get; set; }
[Display(Name = "Policy Description")]
public string ShortDescription { get; set; }
}
2.Controller ActionResult ListPremiumPayment Listed all the transactions in Account_ClientReceiptDistribution.
public ActionResult ListPremiumPayment()
{
var defaultSortBy = Constants.SortField.DebitNoteNo;
var PremPaymentTrans = _accountService.GetTransactionDetailDueForPayment(pagingParameter.PageNumber, pagingParameter.PageSize, pagingParameter.SortBy, pagingParameter.SortDirection, string.Empty, new string[] { });
return View(PremPaymentTrans);
}
ListPremiumPayment View is shown Below: The BeginDate and EndDate Modal input is expected to be populated here so that it could be used to Extract the Transactions that falls within the Date Range. Please Check it if it is possible to use JavaScript or
Ajax or jQuery. The problem with the Modal View
[HttpGet]
public ActionResult CreatePremiumPayment(string actionType, DateTime beginDate, DateTime endDate)
{
ViewBag.OperationName = string.Empty;
if (actionType == "Premium Payment")
ViewBag.OperationName = "Payment";
var entityToCreate = _accountService.GetPolicyDueForPayment();
entityToCreate.TransDate = Helper.GetLocalDate().Date; entityToCreate.BeginDate = beginDate; entityToCreate.EndDate = endDate;
//passing the fields values into Underwriting_InvoicePaid to generate payment transactions.
var result = entityToCreate.Account_ClientReceiptDistribution.Select(a => new Underwriting_InvoicePaid
{
PremiumAmount = a.PremiumAmount,
PolicyCode = a.PolicyCode,
VATAmount = a.VATAmount,
GrossAmount = a.GrossAmount
}).ToList();
entityToCreate.Underwriting_InvoicePaid = result;
ViewBag.ActionType = "Generate Payment"; //Button for Generating Payment on the Form
return View(entityToCreate);
}
Controller ActionResultCreatePremiumPayment
[HttpPost]
public ActionResult CreatePremiumPayment(ClientPaymentViewModel model, string actionType, string operationName)
{
ViewBag.OperationName = operationName;
ViewBag.ActionType = actionType;
if (ModelState.IsValid)
{
ValidationStateDictionary states = new ValidationStateDictionary();
var updated = 0;
if (actionType == "Premium Payment")
{
if (operationName == "Payment")
{
updated = _accountService.AddPRemiumPayment(model, ref states);
}
}
}
else
{
Danger(Constants.Messages.ErrorNotice, true);
return View(model);
}
}
Thank you so much. Any help to make the BeginDate and
EndDate modal works, will be so much appreciated. Feel Free to modify as deem fit to achieve the aim.
Thank you so much for asking me to return to your comment. Yes I can see my mistake. I have restore the model and the view to the previous state. The Model, Controller and view are stated below. When I run the project, it retrieved the data from database
but give error on entering the View:
{"The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[Brokerage.Model.ClientPaymentViewModel]', but this dictionary requires a model item of type 'Brokerage.Model.ClientPaymentViewModel'."}
System.Exception {System.InvalidOperationException}.
I therefore Modify the public IEnumerable<PolicyDetails> PolicyDetailsList { get; set; }
to public IEnumerable<PolicyDetails> PolicyDetails { get; set; }.
However, the error persist. as shown below. I have compared the items on the Database retrieved to the items on the model and they are in order. A copy of the Database repository is pasted below.
I noticed the Header of the List in the View comes from the ClientPaymentViewModel, while the body comes from the PolicyDetails.
Could that be the cause of the Error?
Thank you so much for your perseverance.
public class ClientPaymentViewModel
{
public IList<Account_ClientReceiptDistribution> Account_ClientReceiptDistribution { get; set; }
public IList<Underwriting_InvoicePaid> Underwriting_InvoicePaid { get; set; }
public PaymentExtractionDTO PaymentExtractionDTO { get; set; }
public IEnumerable<PolicyDetails> PolicyDetails { get; set; }
[Display(Name = "Policy Ref_Code")]
public string PolicyRefCode { get; set; }
[Display(Name = "Receipt №")]
public string ReceiptCode { get; set; }
[Display(Name = "DebitNote №")]
public string DebitNoteNo { get; set; }
[Display(Name = "Date")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? TransDate { get; set; }
public string Client { get; set; }
public string TellerNo { get; set; }
[Display(Name = "Premium Amount")]
public decimal? PremiumAmount { get; set; }
[Display(Name = "Net Premium Due")]
public decimal NetPremium { get; set; }
[Display(Name = "Policy Description")]
public string ShortDescription { get; set; }
public string PolicyCode { get; set; }
}
public class PaymentExtractionDTO
{
[Display(Name = "FROM:")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime BeginDate { get; set; }
[Display(Name = "TO:")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime EndDate { get; set; }
}
public class PolicyDetails
{
[Display(Name = "Policy Ref_Code")]
public string PolicyRefCode { get; set; }
[Display(Name = "Receipt №")]
public string ReceiptCode { get; set; }
[Display(Name = "DebitNote №")]
public string DebitNoteNo { get; set; }
[Display(Name = "Date")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? TransDate { get; set; }
public string Client { get; set; }
public string TellerNo { get; set; }
[Display(Name = "Premium Amount")]
public decimal? PremiumAmount { get; set; }
[Display(Name = "Net Premium Due")]
public decimal NetPremium { get; set; }
[Display(Name = "Policy Description")]
public string ShortDescription { get; set; }
public string PolicyCode { get; set; }
}
The View State Now. It's not accepting @using,
therefore I used@Html.BeginForm("CreatePremiumPayment", "AccountController", FormMethod.Post)
I hope it will still work when it gets there?
sql.AppendLine("SELECT a.PolicyRefCode, TransDate, a.ReceiptCode, a.PolicyCode, a.DebitNoteNo, a.TellerNo, b.Name As Client, a.PremiumAmount, a.NetPremium, d.ShortDescription FROM [Account_ClientReceiptDistribution] As a");
sql.AppendLine("INNER JOIN [Underwriting_Client] As b ON a.ClientCode = b.ClientCode");
sql.AppendLine("INNER JOIN [Underwriting_Policy_Code] As d ON a.PolicyCode = d.PolicyCode");
sql.AppendLine("WHERE IsReceiptAlreadyLodged =1 AND IsDebitNoteAlreadyLodged =1) AS TBLALL ");
Thanks a million for your patience and understanding. I have to study your codes as instructed and amended mine with little adjustment to the model and the modal. Eventually it works. However, I must commend you for the technicality behind the solution
to get the challenge resolved, you are highly appreciated. Professionally speaking, the ASP.NET community is truly commended for this
FORUM. it's greatly beneficial.
Member
3 Points
26 Posts
How do I capture Data Between two Dates on IENUMERABLE View Model
Aug 30, 2018 05:41 AM|Lawrence_Ajayi|LINK
Hi guys. Kindly show me how to capture data between two dates (BeginDate and EndDate)on IEnumerable View model. I wanted to use modal form but its not working. The IEnumerable View model is shown below. Kindly demonstrate how I can implement this functionality from this View model below under the
Your anticipated response will be very much appreciated. Any new suggestion on how to handle this with a demos is highly welcome too.
Kind regards
Member
131 Points
78 Posts
Re: How do I capture Data Between two Dates on IENUMERABLE View Model
Aug 30, 2018 07:11 AM|emrulkayes2103|LINK
From your problem i think you need to use view model for Passing list which will populate You table and also the model for you both dates. You need to create a View Model class
try to add something like below in you view
Now you can receive data from of start Date and End date from View.
Hope this will help you.
Member
3 Points
26 Posts
Re: How do I capture Data Between two Dates on IENUMERABLE View Model
Aug 30, 2018 08:18 AM|Lawrence_Ajayi|LINK
Thanks emrulkayes21 for your quick response. Sorry I did not attach the Model. Kindly find the model below. What I intend doing is when the [Payment Extraction] button is clicked. It should display a modal form with Date: FROM:[ ] TO; [ ] waiting for user input. Please add the modal view to the main view above as I find it difficult to add please. My modal view placed below the main view and the Modal Class are pasted below. The Modal views underlines the PaymentExtractionDTO. model in red.
I observed that the @model IEnumerable<Brokerage.Model.ClientPaymentViewModel> declaration on top of the main view is not allowing the Modal view to access the PaymentExtractionDTO. The error message is :
Error 5 'System.Collections.Generic.IEnumerable<Brokerage.Model.ClientPaymentViewModel>' does not contain a definition for 'PaymentExtractionDTO' and no extension method 'PaymentExtractionDTO' accepting a first argument of type 'System.Collections.Generic.IEnumerable<Brokerage.Model.ClientPaymentViewModel>' could be found (are you missing a using directive or an assembly reference?)
What i'm I doing wrongly please? Thanks a million in anticipation of your assistance.
Member
131 Points
78 Posts
Re: How do I capture Data Between two Dates on IENUMERABLE View Model
Aug 30, 2018 10:07 AM|emrulkayes2103|LINK
Yes you can not use @model IEnumerable<Brokerage.Model.ClientPaymentViewModel> because your view has Mixed Content like in one page you want to Show a list and also create a Form. But when you Strongly Typed The View with IEnumerable<Model> then the view will not be allow you to add Strongly Typed for that Model.
I think you are almost near to the Solution. Keep your Modal inside the same view and use the below code for your view
At first Create a Model for your policy attributes
Then make an User Defined Property of PolicyDeatils in your ClientPaymentViewModel like below
Not populate the Exact list for PolicyDetails in you Controller which will somethings like below
Now your view will be like below
Now receive the data in your controller like below
Note: Your are missing adding Form in your Modal
Hope this will help you.
Member
3 Points
26 Posts
Re: How do I capture Data Between two Dates on IENUMERABLE View Model
Aug 30, 2018 03:18 PM|Lawrence_Ajayi|LINK
I quite appreciate your assistance, however, its not working as the PaymentExtractionDTO still shows errors on the modal. You mentioned Partial View in your first reply. How do I get it done using Partial View please.
Many thanks
Member
131 Points
78 Posts
Re: How do I capture Data Between two Dates on IENUMERABLE View Model
Aug 30, 2018 04:20 PM|emrulkayes2103|LINK
Cam you send me your Model, Controller and View File ??? Or paste here the full code in 3 sections 1. Model , 2. Controller, 3. View so that i can try to find what is the exact problem. An also Attach a screen shot of your Error.
Member
3 Points
26 Posts
Re: How do I capture Data Between two Dates on IENUMERABLE View Model
Aug 30, 2018 06:36 PM|Lawrence_Ajayi|LINK
Thank you. I have reconfigured the Model as shown below with Explanations. The data to be retrieved are contained inside Account_ClientReceiptDistribution. First I used IEnumerable to List the full content of the file into a view [ListPremiumPayment] with the intention to using Modal on it to retrieve the Transactions that falls into the [BeginDate] and [EndDate] for payment. These dates were pass as arguments [DateTime beginDate, DateTime endDate] into the [HttpGet] to retrieve the transactions that falls within the Date range, which will then Generate the Payment.
1. Model
2. Controller ActionResult ListPremiumPayment Listed all the transactions in Account_ClientReceiptDistribution.
ListPremiumPayment View is shown Below: The BeginDate and EndDate Modal input is expected to be populated here so that it could be used to Extract the Transactions that falls within the Date Range. Please Check it if it is possible to use JavaScript or Ajax or jQuery. The problem with the Modal View
3. View
Controller ActionResult CreatePremiumPayment
Controller ActionResult CreatePremiumPayment
Thank you so much. Any help to make the BeginDate and EndDate modal works, will be so much appreciated. Feel Free to modify as deem fit to achieve the aim.
Member
131 Points
78 Posts
Re: How do I capture Data Between two Dates on IENUMERABLE View Model
Aug 30, 2018 07:06 PM|emrulkayes2103|LINK
Please try my last comment which has code segment.. May be you do not follow that. try like that try to understand.
Member
3 Points
26 Posts
Re: How do I capture Data Between two Dates on IENUMERABLE View Model
Aug 31, 2018 01:10 AM|Lawrence_Ajayi|LINK
Thank you so much for asking me to return to your comment. Yes I can see my mistake. I have restore the model and the view to the previous state. The Model, Controller and view are stated below. When I run the project, it retrieved the data from database but give error on entering the View:
{"The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[Brokerage.Model.ClientPaymentViewModel]', but this dictionary requires a model item of type 'Brokerage.Model.ClientPaymentViewModel'."} System.Exception {System.InvalidOperationException}.
I therefore Modify the public IEnumerable<PolicyDetails> PolicyDetailsList { get; set; } to public IEnumerable<PolicyDetails> PolicyDetails { get; set; }. However, the error persist. as shown below. I have compared the items on the Database retrieved to the items on the model and they are in order. A copy of the Database repository is pasted below.
I noticed the Header of the List in the View comes from the ClientPaymentViewModel, while the body comes from the PolicyDetails. Could that be the cause of the Error?
Thank you so much for your perseverance.
The View State Now. It's not accepting @using, therefore I used@Html.BeginForm("CreatePremiumPayment", "AccountController", FormMethod.Post) I hope it will still work when it gets there?
Database Repository Retrieved Fields
The ActionResult Methods remain unchanged.
Once again thanks so much. Good morning.
Member
3 Points
26 Posts
Re: How do I capture Data Between two Dates on IENUMERABLE View Model
Aug 31, 2018 02:30 PM|Lawrence_Ajayi|LINK
Thanks a million for your patience and understanding. I have to study your codes as instructed and amended mine with little adjustment to the model and the modal. Eventually it works. However, I must commend you for the technicality behind the solution to get the challenge resolved, you are highly appreciated. Professionally speaking, the ASP.NET community is truly commended for this FORUM. it's greatly beneficial.