Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Display selected value of dropdown list in page

Posted on 2014-12-22
11
Medium Priority
?
59 Views
Last Modified: 2015-01-03
I want to be able to display the value from a dropdown list on a page. You will see a section under the dropdown code <p>Dropdown selection goes here</p>. Here is my code so far:

@model List<Portal2.Models.V_Routings>

@{
    Layout = "~/Views/Shared/_masterLayout.cshtml";
}

<div class="form-group-sm">
    <form action="~/routings" method="post">
        <select class="form-control"name="ddlRoutings" onchange="this.form.submit()" id="ddlRoutings">
            <option value=""></option>
            <option value="Band Saw">Band Saw</option>
            <option value="Drillpress">Drillpress</option>
            <option value="Fab">Fab</option>
            <option value="Fadal 3016">Fadal 3016</option>
            <option value="Fadal 4020">Fadal 4020</option>
            <option value="Fadal 8030">Fadal 8030</option>
            <option value="Fineline">Fineline</option>
            <option value="Flexarm">Flexarm</option>
            <option value="Laser">Laser</option>
            <option value="Mach.Shop">Mach.Shop</option>
            <option value="Mazakqt200">Mazakqt200</option>
            <option value="Part Mark">Part Mark</option>
            <option value="Pem-Press">Pem-Press</option>
            <option value="Powder">Powder</option>
            <option value="Pressbrake">Pressbrake</option>
            <option value="QC">QC</option>
            <option value="Welding">Welding</option>
            <option value="Sandblast">Sandblast</option>
            <option value="WJ 1 Head">WJ 1 Head</option>

        </select>
    </form>
</div>

<p>Dropdown selection goes here</p>

<table class="table" cellspacing="0" cellpadding="4" rules="all" border="1" id="cphMain_GridView1" style="color:#333333;border-collapse:collapse;">
    <tbody>
        <tr>
            <th scope="col">Promised Date</th>
            <th scope="col">Job</th>
            <th scope="col">Customer</th>
            <th scope="col">Part Number</th>
            <th scope="col">Description</th>
            <th scope="col">Rev</th>
            <th scope="col">Promised Quantity</th>
            <th scope="col">Remaining Quantity</th>
            <th scope="col">Status</th>
            <th scope="col">Comment</th>
        </tr>
        @foreach (var item in Model)
            {
                var cssName = "";
                if (item.Promised_Date < DateTime.Now.Date)
                { cssName = "passed"; }
                else if (item.Promised_Date == DateTime.Now.Date)
                { cssName = "current"; }
                <tr class="@cssName">
                    <td>@item.Promised_Date.ToString("MM/dd/yyyy")</td>
                    <td><a href="/routing/jobdetails/@item.Job">@item.Job</a></td>
                    <td>@item.Customer</td>
                    <td>@item.Part_Number</td>
                    <td>@item.Description</td>
                    <td>@item.Rev</td>
                    <td>@item.Promised_Quantity</td>
                    <td>@item.Remaining_Quantity</td>
                    <td>@item.Status</td>
                    <td>@item.Comment</td>
                </tr>
            }
    </tbody>
</table>

Open in new window

0
Comment
Question by:princeservice
  • 6
  • 5
11 Comments
 
LVL 10

Expert Comment

by:Walter Padrón
ID: 40513375
You could modify your Model and add a property that hold the value selected
<p>@Model.SomeProperty</p>

Open in new window

0
 

Author Comment

by:princeservice
ID: 40513386
I am an extreme beginner here. This is the code for my model:

namespace Portal2.Models
{
    using System;
    using System.Collections.Generic;
    
    public partial class V_Routings
    {
        public string Job { get; set; }
        public string Customer { get; set; }
        public string Rev { get; set; }
        public string Part_Number { get; set; }
        public string Description { get; set; }
        public string Status { get; set; }
        public int Promised_Quantity { get; set; }
        public string Order_Unit { get; set; }
        public System.DateTime Promised_Date { get; set; }
        public string Comment { get; set; }
        public string Work_Center { get; set; }
        public string Expr1 { get; set; }
        public Nullable<int> Remaining_Quantity { get; set; }
    }
}

Open in new window


I am trying to put the Work_Center value in the text area.
0
 
LVL 10

Expert Comment

by:Walter Padrón
ID: 40513478
<p>@Model.Work_Center</p>

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:princeservice
ID: 40513500
Thanks for your quick response. I had already tried that. I am getting this:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: 'System.Collections.Generic.List<Portal2.Models.V_Routings>' does not contain a definition for 'Work_Center' and no extension method 'Work_Center' accepting a first argument of type 'System.Collections.Generic.List<Portal2.Models.V_Routings>' could be found (are you missing a using directive or an assembly reference?)

Source Error:


Line 33: </div>
Line 34: <br/>
Line 35: <p>@Model.Work_Center</p>
Line 36:
Line 37: <table class="table table-striped table-bordered" id="cphMain_GridView1">
0
 
LVL 10

Expert Comment

by:Walter Padrón
ID: 40513565
I didn't realize that you specify a List<Portal2.Models.V_Routings>

Suppose the Work_Center is the same in all items returned.
<p>@Model[0].Work_Center</p>

A more maintanable code
   public partial class V_Routings
   {
        public string Work_Center { get; set; }
       // Put other attibutes here ...

        public List<RoutingItems> Items { get; set; }
   }

    public class RoutingItems
    {
        public string Job { get; set; }
        public string Customer { get; set; }
        public string Rev { get; set; }
        public string Part_Number { get; set; }
        public string Description { get; set; }
        public string Status { get; set; }
        public int Promised_Quantity { get; set; }
        public string Order_Unit { get; set; }
        public System.DateTime Promised_Date { get; set; }
        public string Comment { get; set; }
        public string Expr1 { get; set; }
        public Nullable<int> Remaining_Quantity { get; set; }
    }

Open in new window

0
 

Author Comment

by:princeservice
ID: 40513630
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:


Line 32:     </form>
Line 33: </div>
Line 34: <p>@Model[0].Work_Center Routing</p>
Line 35: <br />
Line 36: <table class="table table-striped table-bordered table-condensed" id="cphMain_GridView1">
0
 
LVL 10

Expert Comment

by:Walter Padrón
ID: 40513897
This means your List<Portal2.Models.V_Routings> is empty.

Add a check
<p>
@if ( Model.Any() )
{
    @Model[0].Work_Center
}
</p>

Open in new window

0
 

Author Comment

by:princeservice
ID: 40514305
The table right below that is working and filling with data from the same model.

        @foreach (var item in Model)
            {
                var cssName = "";
                if (item.Promised_Date < DateTime.Now.Date)
                { cssName = "passed"; }
                else if (item.Promised_Date == DateTime.Now.Date)
                { cssName = "current"; }
                <tr class="@cssName">
                    <td>@item.Promised_Date.ToString("MM/dd/yyyy")</td>
                    <td><a href="/routing/jobdetails/@item.Job">@item.Job</a></td>
                    <td>@item.Customer</td>
                    <td>@item.Part_Number</td>
                    <td>@item.Description</td>
                    <td>@item.Rev</td>
                    <td>@item.Promised_Quantity</td>
                    <td>@item.Remaining_Quantity</td>
                    <td>@item.Status</td>
                    <td>@item.Comment</td>
                </tr>
            }
    </tbody>
</table>

Open in new window

0
 
LVL 10

Expert Comment

by:Walter Padrón
ID: 40515195
This works on my computer VS2013 + framework 4.5 + MVC5

Also you should tag the string "Routing"
<p>@Model[0].Work_Center <span>Routing</span></p>
0
 

Accepted Solution

by:
princeservice earned 0 total points
ID: 40521865
Never got a working answer
0
 

Author Closing Comment

by:princeservice
ID: 40528938
Never got a working answer
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question