Solved

Display selected value of dropdown list in page

Posted on 2014-12-22
11
52 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb.net dynamic formulas in runtime 11 62
Syntax error 9 45
IIS Authorization for Web Service 2 22
ASP.NET gridview select textbox on focus 2 0
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

17 Experts available now in Live!

Get 1:1 Help Now