我有一个视图:
@model grepTMVC.Models.TAgentStatHeaderModelList
@{
if (ViewBag.userTypeID == null)
{
Layout = "~/Views/Shared/_InitLayout.cshtml";
}
else if (ViewBag.userTypeID == "TA")
{
Layout = "~/Views/Shared/_TALayout.cshtml";
}
else if (ViewBag.userTypeID == "TR")
{
Layout = "~/Views/Shared/_TRLayout.cshtml";
}
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/media/js/jquery.dataTables.js")" type="text/javascript"></script>
<script src="@Url.Content("~/media/js/jquery.js")" type="text/javascript"></script>
<script src="@Url.Content("~/media/js/jquery.dataTables.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.rating.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.MetaData.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.form.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.rating.pack.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Scripts/jquery.rating.css")" rel="stylesheet" type="text/css" />
@{
ViewBag.Title = "B On Ts";
}
@section SideBar1 {
<ul>
<li><a href="#">Section page 1</a></li>
<li><a href="#">Section page 2</a></li>
<li><a href="#">Section page 3</a></li>
<li><a href="#">Section page 4</a></li>
</ul>
}
@section SideBar2 {
<h3>
Aside heading
</h3>
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan.
}
@{
if (ViewBag.userName != null)
{
<div align="right"><font color="#000000" size="2">User: @ViewBag.userName is logged in</font></div>
}
}
@{
if (ViewBag.Message != null)
{
<p><font color="red" size="2">@ViewBag.Message </font></p>
}
}
@using (Html.BeginForm())
{
<fieldset>
<div>
@{ if (ViewBag.frompage == "_MyTBDetailTA" || ViewBag.frompage == "_OtherTBDetailTA")
{
@Html.ActionLink("Back to List", "MyTBHeaderTA", "", new { style = "font-family:Verdana;font-size:13px" })
}
else
{
@Html.ActionLink("Back to List", "AllTHeaderTR", "", new { style = "font-family:Verdana;font-size:13px" })
}
TempData["l_frompage"] = ViewBag.frompage;
}
</div>
<br />
<legend>Agent Stats</legend>
<br />
<div id="grid">
@{ Html.Grid(Model).Columns(column =>
{
column.For(c => c.providerID).Named("T Agent").HeaderAttributes(@class => "gridheader");
column.For(c => c.noOfB).Named("No. Of B").HeaderAttributes(@class => "gridheader");
column.For(c => c.noOfRates).Named("No. Of Rates").HeaderAttributes(@class => "gridheader");
column.Custom(@<div>
@{
if (@item.avgUserRate > 0 && @item.avgUserRate <= 0.25M)
{
<input class="star {split:4}" type="radio" value = "0.25" name="@item.rateCount" checked="checked" disabled="disabled" title="Very Poor"/>
}
else
{
<input class="star {split:4}" type="radio" value = "0.25" name="@item.rateCount" disabled="disabled" title="Very Poor"/>
}
if (@item.avgUserRate > 0.25M && @item.avgUserRate <= 0.5M)
{
<input class="star {split:4}" type="radio" value = "0.5" name="@item.rateCount" checked="checked" disabled="disabled" title="Very Poor"/>
}
else
{
<input class="star {split:4}" type="radio" value = "0.5" name="@item.rateCount" disabled="disabled" title="Very Poor"/>
}
if (@item.avgUserRate > 0.5M && @item.avgUserRate <= 0.75M)
{
<input class="star {split:4}" type="radio" value = "0.75" name="@item.rateCount" checked="checked" disabled="disabled" title="Very Poor"/>
}
else
{
<input class="star {split:4}" type="radio" value = "0.75" name="@item.rateCount" disabled="disabled" title="Very Poor"/>
}
if (@item.avgUserRate > 0.75M && @item.avgUserRate <= 1M)
{
<input class="star {split:4}" type="radio" value = "1" name="@item.rateCount" checked="checked" disabled="disabled" title="Very Poor"/>
}
else
{
<input class="star {split:4}" type="radio" value = "1" name="@item.rateCount" disabled="disabled" title="Very Poor"/>
}
if (@item.avgUserRate > 1M && @item.avgUserRate <= 1.25M)
{
<input class="star {split:4}" type="radio" value = "1.25" name="@item.rateCount" checked="checked" disabled="disabled" title="Very Poor"/>
}
else
{
<input class="star {split:4}" type="radio" value = "1.25" name="@item.rateCount" disabled="disabled" title="Very Poor"/>
}
if (@item.avgUserRate > 1.25M && @item.avgUserRate <= 1.5M)
{
<input class="star {split:4}" type="radio" value = "1.5" name="@item.rateCount" checked="checked" disabled="disabled" title="Poor"/>
}
else
{
<input class="star {split:4}" type="radio" value = "1.5" name="@item.rateCount" disabled="disabled" title="Poor"/>
}
if (@item.avgUserRate > 1.5M && @item.avgUserRate <= 1.75M)
{
<input class="star {split:4}" type="radio" value = "1.75" name="@item.rateCount" checked="checked" disabled="disabled" title="Poor"/>
}
else
{
<input class="star {split:4}" type="radio" value = "1.75" name="@item.rateCount" disabled="disabled" title="Poor"/>
}
if (@item.avgUserRate > 1.75M && @item.avgUserRate <= 2M)
{
<input class="star {split:4}" type="radio" value = "2" name="@item.rateCount" checked="checked" disabled="disabled" title="Poor"/>
}
else
{
<input class="star {split:4}" type="radio" value = "2" name="@item.rateCount" disabled="disabled" title="Poor"/>
}
if (@item.avgUserRate > 2 && @item.avgUserRate <= 2.25M)
{
<input class="star {split:4}" type="radio" value = "2.25" name="@item.rateCount" checked="checked" disabled="disabled" title="Poor"/>
}
else
{
<input class="star {split:4}" type="radio" value = "2.25" name="@item.rateCount" disabled="disabled" title="Poor"/>
}
if (@item.avgUserRate > 2.25M && @item.avgUserRate <= 2.5M)
{
<input class="star {split:4}" type="radio" value = "2.5" name="@item.rateCount" checked="checked" disabled="disabled" title="Satisfactory"/>
}
else
{
<input class="star {split:4}" type="radio" value = "2.5" name="@item.rateCount" title="Satisfactory"/>
}
if (@item.avgUserRate > 2.5M && @item.avgUserRate <= 2.75M)
{
<input class="star {split:4}" type="radio" value = "2.75" name="@item.rateCount" checked="checked" disabled="disabled" title="Satisfactory"/>
}
else
{
<input class="star {split:4}" type="radio" value = "2.75" name="@item.rateCount" disabled="disabled" title="Satisfactory"/>
}
if (@item.avgUserRate > 2.75M && @item.avgUserRate <= 3M)
{
<input class="star {split:4}" type="radio" value = "3" name="@item.rateCount" checked="checked" disabled="disabled" title="Satisfactory"/>
}
else
{
<input class="star {split:4}" type="radio" value = "3" name="@item.rateCount" disabled="disabled" title="Satisfactory"/>
}
if (@item.avgUserRate > 3M && @item.avgUserRate <= 3.25M)
{
<input class="star {split:4}" type="radio" value = "3.25" name="@item.rateCount" checked="checked" disabled="disabled" title="Satisfactory"/>
}
else
{
<input class="star {split:4}" type="radio" value = "3.25" name="@item.rateCount" title="Satisfactory"/>
}
if (@item.avgUserRate > 3.25M && @item.avgUserRate <= 3.5M)
{
<input class="star {split:4}" type="radio" value = "3.5" name="@item.rateCount" checked="checked" disabled="disabled" title="Good"/>
}
else
{
<input class="star {split:4}" type="radio" value = "3.5" name="@item.rateCount" disabled="disabled" title="Good"/>
}
if (@item.avgUserRate > 3.5M && @item.avgUserRate <= 3.75M)
{
<input class="star {split:4}" type="radio" value = "3.75" name="@item.rateCount" checked="checked" disabled="disabled" title="Good"/>
}
else
{
<input class="star {split:4}" type="radio" value = "3.75" name="@item.rateCount" disabled="disabled" title="Good"/>
}
if (@item.avgUserRate > 3.75M && @item.avgUserRate <= 4M)
{
<input class="star {split:4}" type="radio" value = "4" name="@item.rateCount" checked="checked" disabled="disabled" title="Good"/>
}
else
{
<input class="star {split:4}" type="radio" value = "4" name="@item.rateCount" disabled="disabled" title="Good"/>
}
if (@item.avgUserRate > 4M && @item.avgUserRate <= 4.25M)
{
<input class="star {split:4}" type="radio" value = "4.25" name="@item.rateCount" checked="checked" disabled="disabled" title="Good"/>
}
else
{
<input class="star {split:4}" type="radio" value = "4.25" name="@item.rateCount" disabled="disabled" title="Good"/>
}
if (@item.avgUserRate > 4.25M && @item.avgUserRate <= 4.5M)
{
<input class="star {split:4}" type="radio" value = "4.5" name="@item.rateCount" checked="checked" disabled="disabled" title="Excellent"/>
}
else
{
<input class="star {split:4}" type="radio" value = "4.5" name="@item.rateCount" disabled="disabled" title="Excellent"/>
}
if (@item.avgUserRate > 4.5M && @item.avgUserRate <= 4.75M)
{
<input class="star {split:4}" type="radio" value = "4.75" name="@item.rateCount" checked="checked" disabled="disabled" title="Excellent"/>
}
else
{
<input class="star {split:4}" type="radio" value = "4.75" name="@item.rateCount" disabled="disabled" title="Excellent"/>
}
if (@item.avgUserRate > 4.75M && @item.avgUserRate <= 5M)
{
<input class="star {split:4}" type="radio" value = "5" name="@item.rateCount" checked="checked" disabled="disabled" title="Excellent"/>
}
else
{
<input class="star {split:4}" type="radio" value = "5" name="@item.rateCount" disabled="disabled" title="Excellent"/>
}
}
</div>).Named("Average Rate").HeaderAttributes(@class => "gridheader").Attributes(style => "width:40%");
}).Render();
}
</div>
<script type="text/javascript">
$(function () {
//Placing this prior to your .get() call will ensure the request is not cached
$.ajaxSetup({ cache: false });
$('#grid tbody tr').on('hover', function () {
$(this).toggleClass('clickable');
}).on('click', function () {
var self = this;
$.ajax(
{
type: "POST",
url: "/T/ViewAgentsDetailTR",
data: { providerID: $(this).find('td:eq(0)').text()
},
success: function (data) {
$('#wrapper').html(data);
$(self).off('click');
}
});
});
$(document).ready(function () {
var oTable = $(".grid").dataTable({
"sPaginationType": "full_numbers",
"iDisplayLength": 10,
"bDestroy": true,
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"aoColumnDefs": [{ 'bSortable': false, 'aTargets': [3]}]
}).after('<br />');
});
});
</script>
</fieldset>
}
此视图向我的控制器调用POST方法,该方法调用存储过程。在调试模式下,我确实看到正在填充的模型如下:
try
{
MySqlDataReader rdr1 = command1.ExecuteReader();
TAgentStatHeaderModelList agentStatModList = new TAgentStatHeaderModelList();
int l_rate = 1;
while (rdr1.Read())
{
var model = new TAgentStatHeaderModel();
model.travelDest = rdr1["travelDest"].ToString();
model.userRate = Convert.ToInt32(rdr1["userRate"]);
model.rateCount = l_rate++;
model.comments = rdr1["vComments"].ToString();
agentStatModList.Add(model);
}
rdr1.Close();
dbcontroller1.conn.Close();
return PartialView("_ViewAgentsDetailTR", agentStatModList);
}
但它永远不会进入我的PartialVIEW,即使在我的控制器中,我看到它达到了这一点,让模型正确显示数据
我的partialView定义如下:
@model IEnumerable<grepTMVC.Models.TravelAgentStatHeaderModel>
@{
if (ViewBag.userTypeID == null)
{
Layout = "~/Views/Shared/_InitLayout.cshtml";
}
else if (ViewBag.userTypeID == "TA")
{
Layout = "~/Views/Shared/_TAPartialLayout.cshtml";
}
else if (ViewBag.userTypeID == "TR")
{
Layout = "~/Views/Shared/_TRPartialLayout.cshtml";
}
}
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
@section SideBar1 {
<ul>
<li><a href="#">Section page 1</a></li>
<li><a href="#">Section page 2</a></li>
<li><a href="#">Section page 3</a></li>
<li><a href="#">Section page 4</a></li>
</ul>
}
@section SideBar2 {
<h3>
Aside heading
</h3>
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan.
}
@using (Html.BeginForm())
{
<div align="right"><font color="#000000" size="2">User: @ViewBag.userName is logged in</font></div>
<fieldset>
@foreach (var item in Model)
{
<div>
@{
@Html.ActionLink("Back to list", "ViewAgentsHeaderTR", "T", new { style = "font-family:Verdana;font-size:13px" })
}
</div>
}
<br />
<legend>Detail Ratings</legend>
<table class="tabledetail">
@foreach (var item in Model)
{
<tr>
<th class="thdetail">
TD
</th>
<td class="tddetail">
@Html.DisplayFor(modelItem => item.tD)
</td>
</tr>
<tr>
<th class="thdetail">
Comments
</th>
<td class="tddetail">
<div style="height: 100px; width:700px; overflow: hidden">
@Html.DisplayFor(modelItem => item.comments)
</div>
</td>
</tr>
}
</table>
</fieldset>
<br />
}
确定,
我删除了try / catch块并将PartialView更改为: @model grepTMVC.Models.TAgentStatHeaderModelList
我的模型是这样的: 公共类TAgentStatHeaderModel { public Int64 providerID {get;组; }
public Decimal avgUserRate { get; set; }
public Int32 noOfRates { get; set; }
public int rateCount { get; set; }
public int userRate { get; set; }
public string comments { get; set; }
}
public class TAgentStatHeaderModelList : List<TAgentStatHeaderModel>
{
}
然而,一切都没有改变。我没有看到错误消息。当我点击我的网格行时,没有任何反应。在调试模式下,它通过我的存储过程并添加到模型,5行。此后,它尝试调用PartialView,但它不显示