Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a drop down in View01 and and i need to set selected value of this drop down to lable in view02.Can any one explain me about this with example.

What I have tried:

In view1-dropdown

HTML
<select class="form-control"id="n">
                                   <option>Select Type</option>
                                   <option>A </option>
                                   <option>B </option>
                                   <option>C </option>
                                   <option>D </option>
                                   <option>E</option>
                               </select>



View2-lable

<label class="col-md-3 control-label">Notification Type</label>
Posted
Updated 31-May-18 0:09am
Comments
F-ES Sitecore 14-Oct-16 4:13am    
Via a form submission? Via javascript? Via ajax? Is the other view a new page? A partial view nested inside the same view? A partial view at the same level as this view? You'll need to explain what it is you're trying to do in more detail as it affects the solution.
T_Sub 17-Oct-16 7:04am    
It dose not matter Via any way
Karthik_Mahalingam 18-Oct-16 5:26am    
Always use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.
Karthik_Mahalingam 18-Oct-16 5:27am    
is the view a new page?

Solved In this Way,

in my view,

HTML
@using (Html.BeginForm())
            {
                @Html.DropDownList("type", new List<SelectListItem>
        {

            new SelectListItem {Text = "A", Value ="A "},
            new SelectListItem {Text = "B", Value = "B "},
            new SelectListItem {Text="C", Value = "C "},
             new SelectListItem {Text="D ", Value = "D "},
          
            }, "Select Type", new { @class = "Form-Control" }
        )
                <button type="submit" value="Submit" name="Submit" class="btn green-sharp btn-outline  btn-block sbold uppercase">Proceed</button>
            }


And in my Controller,

C#
[HttpPost]
       public ActionResult gettype (string type)
       {
           string value = type;
           return RedirectToAction("TargetView", "ActionMethod", new { type1 = type});
       }



In TargetView'Action method,

C#
public ActionResult RequestNPD(string type)
       {
           string q= Request.QueryString["type1"];
           ViewBag.test = q;


           return View();

       }



In Target View,

C#
<label class="col-md-3 control-label">@ViewBag.test </label>




Thank You !
 
Share this answer
 
<select class="form-control"id="droplist" runat="server">
<option>Select Type</option>
<option>A </option>
<option>B </option>
<option>C </option>
<option>D </option>
<option>E</option>
</select>
<label class="col-md-3 control-label" id="label" runat="server"> Notification
Type</label>

C#
string droplist= droplist.SelectedValue;
label= droplist;
 
Share this answer
 
Comments
T_Sub 17-Oct-16 7:10am    
Actually It's About Between Two Views In mvc, Not a View and Back end,Anyway thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900