Asp.net 获取ViewBag的干净值
在控制器中,我设置值:Asp.net 获取ViewBag的干净值,asp.net,asp.net-mvc,razor,Asp.net,Asp.net Mvc,Razor,在控制器中,我设置值: ViewBag.incremento = 5; 我有以下看法: @model IEnumerable<Gestor.Models.PlanejVenda> @{ ViewBag.Title = "Índice"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Índice</h2> <p> @Html.ActionLink("Criar novo planejamen
ViewBag.incremento = 5;
我有以下看法:
@model IEnumerable<Gestor.Models.PlanejVenda>
@{
ViewBag.Title = "Índice";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Índice</h2>
<p>
@Html.ActionLink("Criar novo planejamento de compra", "Create")
</p>
<div class="row">
<div class="col-md-6">
@using (Html.BeginForm("Search", "PlanejVendas", FormMethod.Post))
{
<p>
Código: @Html.TextBox("search")
<input type="submit" value="Procurar" />
</p>
}
</div>
<div class="col-md-6">
@using (Html.BeginForm("Search", "PlanejVendas", FormMethod.Post))
{
<p>
Incremento Global: @Html.TextBox("search", new {@ViewBag.incremento })
<input type="submit" value="Confirmar" />
</p>
}
</div>
</div>
<table class="table table-hover">
<tr>
Regula table here showing Ok
@model IEnumerable
@{
ViewBag.Title=“Índice”;
Layout=“~/Views/Shared/_Layout.cshtml”;
}
Índice
@ActionLink(“Criar novo planejamento de compra”,“Create”)
@使用(Html.BeginForm(“Search”、“PlanejVendas”、FormMethod.Post))
{
Código:@Html.TextBox(“搜索”)
}
@使用(Html.BeginForm(“Search”、“PlanejVendas”、FormMethod.Post))
{
Incremento全局:@Html.TextBox(“搜索”,新{@ViewBag.Incremento})
}
这里的规则表显示Ok
我希望我将拥有文本框中的控件设置的干净值5。但它显示:“{incremento=5}”
如何仅获取ViewBag的值,在示例中仅获取数字5?您可以尝试
@Html.TextBox("search", (string)@ViewBag.incremento)
而不是
@Html.TextBox("search", new { @ViewBag.incremento })
你可以试试
@Html.TextBox("search", (string)@ViewBag.incremento)
而不是
@Html.TextBox("search", new { @ViewBag.incremento })
试试这个:
Incremento Global:@Html.TextBox(“搜索”,新的{@value=ViewBag.Incremento})
试试这个:
Incremento Global:@Html.TextBox(“搜索”,新建{@value=ViewBag.Incremento})
将ViewBag
从文本框中分离出来<代码>视图包
返回需要转换为正确类型的对象集合
对于测试,忽略查看包,并使用常量
new
所做的是创建一个匿名类型,而不是一个值。试一试
@Html.TextBox("search", "5")
如果可行,则按照D-Shih的答案将ViewBag项转换为字符串。将
ViewBag
从文本框中分离出来<代码>视图包
返回需要转换为正确类型的对象集合
对于测试,忽略查看包,并使用常量
new
所做的是创建一个匿名类型,而不是一个值。试一试
@Html.TextBox("search", "5")
如果可行,那么将ViewBag项转换为字符串,如D-Shih的答案所示