本文介绍了如何在MVC中将值从一个视图传递到另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在View01中有一个下拉菜单,我需要在view02中将此下拉菜单的选定值设置为lable。任何人都可以通过示例向我解释这个。
我尝试过:
在view1-dropdown中
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
<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>通知类型< / label>
View2-lable
<label class="col-md-3 control-label">Notification Type</label>
推荐答案
@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,
[HttpPost]
public ActionResult gettype (string type)
{
string value = type;
return RedirectToAction("TargetView", "ActionMethod", new { type1 = type});
}
在TargetView'Action方法中,
In TargetView'Action method,
public ActionResult RequestNPD(string type)
{
string q= Request.QueryString["type1"];
ViewBag.test = q;
return View();
}
在目标视图中,
In Target View,
<label class="col-md-3 control-label">@ViewBag.test </label>
$ / b
谢谢!
Thank You !
这篇关于如何在MVC中将值从一个视图传递到另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!