I encountered a
System.InvalidCastException: Unable to cast object of type 'WhereSelectListIterator`2[RateApp.Pages.Index+InQuestion,System.Decimal]' to type 'System.IConvertible'. at System.Convert.ToDecimal(Object value) at RateApp.Pages.Index.Submit()
@page "/"
@using System.Text;
@using System.Net.Http.Headers;
@using Microsoft.AspNetCore.Components;
@using Newtonsoft.Json;
@using RateApp.Models;
@exp
<table class="table">
<thead>
<tr>
<th>DaysBegin</th>
<th>DaysEnd</th>
<th>Interest</th>
<th>SrInterest</th>
</tr>
</thead>
<tbody>
@foreach (InQuestion inques in Questions)
{
// Pass the Dto properties to the component
<tr>
<td>@inques.DaysBegin</td>
<td>@inques.DaysEnd</td>
<td>@inques.Interest</td>
<td>@inques.SrInterest</td>
</tr>}
</tbody>
</table>
<div class="row">
<div class="col-md-3">
<p>Deposit Amount</p>
</div>
<div class="col-md-4">
<input placeholder="Deposit Amount" @bind="@amount" />
</div>
</div>
<br />
<div class="row">
<div class="col-md-3">
<p>Months</p>
</div>
<div class="col-md-4">
<input placeholder="Months" @bind="@months" />
</div>
</div>
<div>
<button type="submit" @onclick="Submit" >Submit</button>
</div>
<div>
<div class="col-md-3">
<p>Interest</p>
</div>
<div>@interest</div>
</div>
@code {
public class InQuestion
{
public int No { get; set; }
public int DaysBegin { get; set; }
public int DaysEnd { get; set; }
public decimal Interest { get; set; }
public decimal SrInterest { get; set; }
}
public string exp;
public string codex; public string jsonstring ; public bool statcode;
List<InQuestion> Questions = new List<InQuestion>();
public int number;int months ;decimal interest; int totalquestions; int maxnumber;int amount;
protected override async Task OnInitializedAsync()
{
string jwturl = "https://quizapijwt.azurewebsites.net/api/";
using (var client1 = new HttpClient())
{
client1.BaseAddress = new Uri(jwturl);
client1.DefaultRequestHeaders.Clear();
client1.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client1.GetAsync("RateCards");
if (response.IsSuccessStatusCode)
{
//Storing the response details recieved from web api
jsonstring = await response.Content.ReadAsStringAsync();
try
{
Questions = JsonConvert.DeserializeObject<List<InQuestion>>(jsonstring);
}
catch (Exception ex)
{ }
// maxnumber=(from e in Questions select e.No).Max();
}
}
}
private void Submit()
{
try
{
decimal days = months * 30;
var queryint = from l in Questions
where l.DaysBegin >= days
&& l.DaysEnd <= days
select l.Interest;
decimal finalint = Convert.ToDecimal(queryint);
decimal amt = amount;
decimal factor = 12;
interest = Decimal.Multiply(amt, finalint) / factor;
}
catch (Exception ex)
{
exp=ex.ToString();
}
}
}