Solved

Display selected value of dropdown list in page

Posted on 2014-12-22
11
53 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Displaying a web form as a modal popup dialog box. 4 30
Reading the Web.Config using IIS 7.5? 4 36
encoding an href string 2 20
asp enable view state 1 24
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 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