Solved

Display selected value of dropdown list in page

Posted on 2014-12-22
11
51 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
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now