【发布时间】:2015-12-18 21:35:32
【问题描述】:
我有一个下拉列表,用户选择某些东西,然后它应该将选定的选项发送到我的控制器并将其保存在 viewbag 上,然后我的控制器返回一个新视图,在新视图中我的表体应该使用 viewbag我的模型中的一条语句的项目,但由于某种原因,当用户选择该选项时没有任何反应..控制器不会触发新视图或传递选定的选项 这是我的控制器
namespace Arpon.Web.Brain.Pos.Controllers
{
public class HomePosController : BaseController
{
//
// GET: /HomePos/
public ActionResult Index()
{
var db = new ArponClientPosContext();
return View("~/Views/HomePos/Index.cshtml", db.Pos.ToList());
}
public ActionResult SimpleInterest(String pdvlist)
{
var db = new ArponClientPosContext();
SimpleInterestModel model = new SimpleInterestModel();
ViewBag.key1 = "0";
ViewBag.key1 = pdvlist;
return View("~/Views/HomePos/IndexF.cshtml", db.Pos.ToList());
}
}
}
还有我的观点:
@using Arpon.Web.Loader.Utils.Helpers;
@model ICollection<Arpon.Web.Brain.Pos.Models.Pos>
@ViewBag.key1
<script>
onDocExtendedLoad(
function run() {
var PdvId = document.getElementById("pdvlist").value;
$('select[name=pdvlist]').change(function () { alert($(this).val()); });
}
);
</script>
<div class="page-title">
<i class="fa fa-bar-chart-o"></i>
<h3>POS</h3>
</div>
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-12 sortable">
<div class="grid simple vertical green">
<div class="grid-title no-border">
<h4>@this.FP("Punto de Venta")</h4>
<div class="tools">
<a href="javascript:;" class="collapse"></a>
<a href="javascript:;" class="reload"></a>
</div>
</div>
<div class="grid-body no-border">
<div class="p-l-20 p-r-20 p-b-10 p-t-10 b-b b-grey">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<h5 class="bold pull-left m-r-5">@this.FP("lbl.loader.date")</h5>
<div class="controls">
<div class="input-append success no-padding">
<div id="reportrange" class="pull-right div-daterangepicker">
<i class="fa fa-calendar fa-lg"></i>
<span>@date.ToString("d MMMM, yyyy") - @date.ToString("d MMMM, yyyy")</span> <b class="caret"></b>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<h5 class="bold pull-left m-r-5">@this.FP("Restaurante")</h5>
<div class="controls">
<div class="input-append success no-padding">
<select class="ctl-source">
<option value="">Todos</option>
<option value="DE">Desayuno</option>
<option value="CO">Comida</option>
<option value="CE">Cena</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<h5 class="bold pull-left m-r-5">@this.FP("PDV")</h5>
<div class="controls">
<div class="input-append success no-padding">
@using (Html.BeginForm())
{
<select id="pdvlist" name="pdvlist" class="ctl-source" onchange="run()">
<option value=" ">Todos</option>
@foreach (var item in Model.Select(l => l.Pdv).Distinct())
{
<option value="@item">@item</option>
}
</select>
<input type="submit" value="Actualizar" />
}
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row" id="dateWidgetIncomeBanquetPanel">
<table class="table table-hover no-more-tables table-iconmebanquet-detail">
<thead>
<tr>
<th style="">Platillo</th>
<th style="">PV</th>
<th style="">1</th>
<th style="">2</th>
<th style="">3</th>
<th style="">4</th>
<th style="">5</th>
<th style="">6</th>
<th style="">7</th>
<th style="">8</th>
<th style="">9</th>
<th style="">10</th>
<th style="">11</th>
<th style="">12</th>
<th style="">13</th>
<th style="">14</th>
<th style="">15</th>
<th style="">16</th>
<th style="">17</th>
<th style="">18</th>
<th style="">19</th>
<th style="">20</th>
<th style="">21</th>
<th style="">22</th>
<th style="">23</th>
<th style="">24</th>
<th style="">25</th>
<th style="">26</th>
<th style="">27</th>
<th style="">28</th>
<th>Total</th>
<th>Venta</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
var total = 0;
decimal costo = 0;
for (int i = 1; i <= 28; i++)
{
var value = 0;
if (item.Fecha.Day == i) { value = item.Cantidad; costo = costo + item.Total; }
total += value;
}
<tr>
<td>@item.Descripcion</td>
<td>@((costo / total).ToString("C"))</td>
@for (int i = 1; i <= 28; i++)
{
var value = 0;
int month = item.Fecha.Month;
if (item.Fecha.Day == i) { value = item.Cantidad; }
<td>
<a href="javascript:void(0)" data-toggle="popover"
data-html="true" data-original-title="@i/@month/2015" data-placement="bottom" data-content="Producto: @item.Descripcion<br />PV:@((costo / total).ToString("C"))<br />Total:@value<br />Venta:@(((costo / total) * value).ToString("C"))" data-trigger="hover">@value</a>
</td>
}
<td>@total</td>
<td>@(((costo / total) * total).ToString("C"))</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
我做错了什么? 任何帮助将不胜感激
【问题讨论】:
-
您将帖子返回到 Index()
, notSimpleInterest(). If you want to post toSimpleInterest()` 然后您需要在BeginForm()方法中指定操作名称。 javascriptRun()方法的目的是什么? -
我添加了 run 方法,因为我选择了执行 run() onchange 的选项,但也没有工作,我如何在 beginForm() 中指定操作?
-
@using (Html.BeginForm("SimpleInterest", yourControllerName, FormMethod.Post)) { ... -
只是
"HomePos"(不是Arpon.Web.Brain.Pos.Controllers.HomePosController)
标签: c# asp.net-mvc-4 razor controller