Sum values from two columns in View MVC - asp.net-mvc

I would like to sum values I get from two columns, these values are added from the data collected in View page based on customers so adding it in a controller from database is not an option as far as I know, I could be wrong
Any help would be appreciated.
I can get sum of two columns individually but can't get sum of two columns.
<table class="table">
<tr>
<th>
#Html.DisplayNameFor(model => model.PkgBasePrice)
</th>
<th>
#Html.DisplayNameFor(model => model.Description)
</th>
<th>
#Html.DisplayNameFor(model => model.BasePrice)
</th>
</tr>
#foreach (var item in Model.Where(ModelItem =>
ModelItem.CustomerId.Equals(Session["CustomerId"])))
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.PkgBasePrice)
</td>
<td>
#Html.DisplayFor(modelItem => item.Description)
</td>
<td>
#Html.DisplayFor(modelItem => item.BasePrice)
</td>
</tr>
}
</table>
<h2>
Package Total: $#Model.Where(c =>
c.CustomerId.Equals(Session["CustomerId"])).Sum(b => b.PkgBasePrice)
</h2>
<h2>
Product Total: $#Model.Where(c =>
c.CustomerId.Equals(Session["CustomerId"])).Sum(b => b.BasePrice)
</h2>
I would like to get sum of PkgBasePrice and BasePrice in one amount

Since you already have the two individual sums you want to combine, you can add the two sums you have together as follows:
#(#Model.Where(c => c.CustomerId.Equals(Session["CustomerId"])).Sum(b => b.PkgBasePrice) +
#Model.Where(c => c.CustomerId.Equals(Session["CustomerId"])).Sum(b => b.BasePrice))

Related

Is there a way I can add and bind checkboxes to my MVC Table

I am trying to add a checkbox so I can selects a row from my list and from there use that row to generate a letter.
I was wondering how I would be able to add a checkbox and bind it to the data I have tried a few ways using something similar to:
checkbox(m => m[i].Lesson)
However it would never accept the i in brackets and come up with an error. below is the layout of my index for the lessons model currently.
Here is the Lessons Index:
#model IEnumerable<FinalMusicApp.Models.Lesson>
#{
ViewBag.Title = "Index";
}
<h2>Lessons</h2>
<p>
#Html.ActionLink("Create New", "Create")
</p>
#using (Html.BeginForm("Index", "Students", FormMethod.Get))
{
//Search options
<b>Search Options: </b> #Html.RadioButton("Option", "Instrument")<text>Instrument</text>#Html.RadioButton("Option", "Tutor")<text>Tutor</text>#Html.RadioButton("Option", "Term")<text>Term</text>#Html.TextBox("Search")
<input type="submit" name="submit" value="Search" />
}
<form method="post">
<table class="table">
<tr>
<th>
#Html.DisplayNameFor(model => model.IsChecked)
</th>
<th>
#Html.DisplayNameFor(model => model.LessonDate)
</th>
<th>
#Html.DisplayNameFor(model => model.LessonTime)
</th>
<th>
#Html.DisplayNameFor(model => model.Duration.TimeTaken)
</th>
<th>
#Html.DisplayNameFor(model => model.Instrument.InstrumentName)
</th>
<th>
#Html.DisplayNameFor(model => model.Letter.Paid)
</th>
<th>
#Html.DisplayNameFor(model => model.Student.FullName)
</th>
<th>
#Html.DisplayNameFor(model => model.Tutor.TutorName)
</th>
<th>
CRUD
</th>
<th>
Make a letter
</th>
</tr>
#foreach (var item in Model)
{
<tr>
<td>
#Html.CheckBoxFor(modelItem => item.IsChecked)
</td>
<td>
#Html.DisplayFor(modelItem => item.LessonDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.LessonTime)
</td>
<td>
#Html.DisplayFor(modelItem => item.Duration.TimeTaken)
</td>
<td>
#Html.DisplayFor(modelItem => item.Instrument.InstrumentName)
</td>
<td>
#Html.DisplayFor(modelItem => item.Letter.Paid)
</td>
<td>
#Html.DisplayFor(modelItem => item.Student.FullName)
</td>
<td>
#Html.DisplayFor(modelItem => item.Tutor.TutorName)
</td>
<td>
#Html.ActionLink("Edit", "Edit", new { id = item.LessonId }) |
#Html.ActionLink("Details", "Details", new { id = item.LessonId }) |
#Html.ActionLink("Delete", "Delete", new { id = item.LessonId })
</td>
<td>
#Html.ActionLink("Generate Letter", "Create", "Letters")
</td>
</tr>
}
</table>
</form>
I am trying to add a checkbox so I can selects a row from my list
Do you want something like below?
In the view add a checkbox, for example I use the property CourseName in my model instead, you can use your property:
#Html.CheckBox("CourseName", new { value = item.CourseName })
#Html.DisplayFor(modelItem => item.CourseName)
Then in the controller, we can get CourseName value, and get other property value accord to the CourseName, but we need load the list again, we cannot send the full list from view to controller :
var courserow = model.FirstOrDefault(m => m.CourseName == CourseName);
result:

How to put a row in red with Razor in MVC5

I have a table, which I want to mark when the real stock is less than the minimum stock, for that I'm going to render the view using Razor, but I'm not getting results
I enclose my view that contains the table that we wish to intervene
<table class="table table-bordered table-hover table-condensed">
<tr>
<th>
#Html.DisplayNameFor(model => model.First().v_Nombre)
</th>
<th>
#Html.DisplayNameFor(model => model.First().StockReal)
</th>
<th>
#Html.DisplayNameFor(model => model.First().StockMinimo)
</th>
<th></th>
</tr>
#foreach (var item in Model)
{
var fila = string.Empty;
if(item.StockReal < item.StockMinimo)
{
fila = "danger";
}
<tr class="#fila">
<td>
#Html.DisplayFor(modelItem => item.v_Nombre)
</td>
<td>
#Html.DisplayFor(modelItem => item.StockReal)
</td>
<td>
#Html.DisplayFor(modelItem => item.StockMinimo)
</td>
<td>
Editar
</td>
</tr>
}
</table>
Expected behavior: that the row where the real stock is less than the minimum stock turns red
Behavior Achieved: No change in my view
what am I doing wrong? What is missing in my Razor code? any help for me?
In bootstrap 4 the class is table-danger so change your code:
if(item.StockReal < item.StockMinimo)
{
fila = "table-danger";
}

Redirect to Link from Link saved in database

I am developing an Web Application in MVC.
I have added a link in Database eg:"www.google.com", I want user to redirect to Google on click.
I tried in many ways but getting the controller in address bar "eg:http://localhost:/Home/www.google.com"
View Code
<table class="table" style="margin-top:10px;">
<tr>
<th>
Sr. No.
</th>
<th>
Name
</th>
<th>
Details
</th>
<th>
Status
</th>
<th>
Tracking No.
</th>
<th>
Tack Order
</th>
<th>
Ordered On
</th>
</tr>
#{int row = 0;} #foreach (var item in Model) { if (item.PaymentSuccessfull == true) {
<tr>
<td>
#(row += 1)
</td>
<td>
#Html.DisplayFor(modelItem => item.DeliveryDetail.FirstName)
</td>
<td>
Order Details
</td>
<td>
#Html.DisplayFor(modelItem => item.Status)
</td>
<td>
#Html.DisplayFor(modelItem => item.TrackingId)
</td>
<td>
//Here I want user to redirect to Google on click
Track
</td>
<td>
#Html.DisplayFor(modelItem => item.DateTime)
</td>
</tr>
} }
Help is appreciated.
Thanks in advance.
You must store the protocol with the rest of the URL.
so:
www.google.com
becomes:
http://www.google.com

MVC Entity Framework INDEX page format

I have a new MVC Entity Framework Application. When it created the Index List page - it looks like the Headers are ran together. Have small size fields and the field names are longer than the fields. How to format that page to make Header spaced out so it doesn't all run together.
Could not post a pic - something like this - sorry the data line ran together on the past.
RE NUMINT RE NAME
1 I SHAWN NEWT
#model IEnumerable<MTSapp.Models.mts_rename>
#{ ViewBag.Title = "Index"; }
<h2>Index</h2>
<p> #Html.ActionLink("Create New", "Create") </p>
<table>
<tr>
<th> #Html.DisplayNameFor(model => model.A_RENO) </th>
<th> #Html.DisplayNameFor(model => model.A_INACT) </th>
<th> #Html.DisplayNameFor(model => model.A_NAME) </th>
<th></th>
</tr>
#foreach (var item in Model)
{
<tr>
<td> #Html.DisplayFor(modelItem => item.A_RENO) </td>
<td> #Html.DisplayFor(modelItem => item.A_INACT) </td>
<td> #Html.DisplayFor(modelItem => item.A_NAME) </td>
</tr>
}
</table>
Is the page using a table or some type of grid? You may need to apply some CSS rules to get the page nicely formatted. Does the page have any CSS styling yet?

Simple MVC4 Razor Table UI Filtering using Angularjs

I have a simpe MVC 4 application. this is my first ever ASP.NET MVC project and I completed the View-Controller-Model binding and getting the results in he table format. Now my challenge is to filter the data using AngularJS. I googled a lot. All the examples I have seen so far are either advanced or hardcoded values in the app.js controller. Can someone please guide me how to implement the simple filtering using AngularJs. What do I need do achieve the same.
Below is my View (Index.html)
#model IEnumerable<ProjectForm.Models.CreateProjectModel>
#{
ViewBag.Title = "Browse Tasks";
}
#using System.Web.Optimization
<h2>All Task List</h2>
<table class="table table-striped table-condensed table-hover table-bordered table-nonfluid">
<tr>
<th>
#Html.DisplayNameFor(model => model.task_id)
</th>
<th>
#Html.DisplayNameFor(model => model.task_desc)
</th>
<th>
#Html.DisplayNameFor(model => model.task_type)
</th>
<th>
#Html.DisplayNameFor(model => model.Priority)
</th>
<th>
#Html.DisplayNameFor(model => model.Task_status)
</th>
<th>
#Html.DisplayNameFor(model => model.Requester)
</th>
<th>
#Html.DisplayNameFor(model => model.RequestDate)
</th>
<th>
#Html.DisplayNameFor(model => model.busowner)
</th>
<th>
#Html.DisplayNameFor(model => model.devowner)
</th>
<th>
#Html.DisplayNameFor(model => model.StartDate)
</th>
<th>
#Html.DisplayNameFor(model => model.est_effort)
</th>
<th>
#Html.DisplayNameFor(model => model.Complete_date)
</th>
<th>
#Html.DisplayNameFor(model => model.act_effort)
</th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.task_id)
</td>
<td>
#Html.DisplayFor(modelItem => item.task_desc)
</td>
<td>
#Html.DisplayFor(modelItem => item.task_type)
</td>
<td>
#Html.DisplayFor(modelItem => item.Priority)
</td>
<td>
#Html.DisplayFor(modelItem => item.Task_status)
</td>
<td>
#Html.DisplayFor(modelItem => item.Requester)
</td>
<td>
#Html.DisplayFor(modelItem => item.RequestDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.busowner)
</td>
<td>
#Html.DisplayFor(modelItem => item.devowner)
</td>
<td>
#Html.DisplayFor(modelItem => item.StartDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.est_effort)
</td>
<td>
#Html.DisplayFor(modelItem => item.Complete_date)
</td>
<td>
#Html.DisplayFor(modelItem => item.act_effort)
</td>
</tr>
}
</table>
</body>
I also found a most closest solution in Stack Overflow, but it is not complete.
Sorting MVC razor UI table using Angularjs

Resources