这是我的模型类
###patch start###
from mpl_toolkits.mplot3d.axis3d import Axis
def _get_coord_info_new(self, renderer):
mins, maxs, cs, deltas, tc, highs = self._get_coord_info_old(renderer)
correction = deltas * [1.0/4 + 6.0/11,
1.0/4 + 6.0/11,
1.0/4]
mins += correction
maxs -= correction
return mins, maxs, cs, deltas, tc, highs
if not hasattr(Axis, "_get_coord_info_old"):
Axis._get_coord_info_old = Axis._get_coord_info
Axis._get_coord_info = _get_coord_info_new
###patch end###
我的控制者
public class SurveyModel
{
public SurveyModel()
{
this.Name = string.Empty;
this.Url = string.Empty;
}
[Key]
public string Name { get; set; }
public int? ResponseCount { get; set; }
public string Url { get; set; }
public SurveyModel(SurveyMonkey.Containers.Survey survey)
{
Name = survey.Nickname;
ResponseCount = survey.ResponseCount;
Url = survey.AnalyzeUrl;
}
我的观点
public class SurveysController : Controller
{
private SurveyMonkeyApi _surveyMonkey;
public SurveysController(ISurveyMonkeyApiFactory factory)
{
// _apiFactory = factory.Create();
}
public SurveysController()
{
}
// GET: Surveys
public ActionResult Index()
{
using (var api = new SurveyMonkeyApi("zgSdm04SEefy09ONaxV6b0z5rDOoRHXffGXMAasySfAyxUfCTN4x3AR9IyK5NVoRrBKB27bT-SMlbbL0dI2vUNYQiRNZqbslM0-KATC9JwWblgx4mieUwNxoDzC54lxe"))
{
IEnumerable<Survey> surveys = api.GetSurveyList();
return View(surveys.ToList());
}
}
}
我保持这个错误
传递到字典中的模型项的类型为'System.Collections.Generic.List`1 [SurveyMonkey.Containers.Survey]'
但此词典需要 @model IEnumerable<SimpleSurveyTest.Models.SurveyModel>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.ResponseCount)
</th>
<th>
@Html.DisplayNameFor(model => model.Url)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.ResponseCount)
</td>
<td>
@Html.DisplayFor(modelItem => item.Url)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Name }) |
@Html.ActionLink("Details", "Details", new { id=item.Name }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Name })
</td>
</tr>
}
</table>
答案 0 :(得分:0)
在这种方法中 ) // GET:调查
public ActionResult Index()
{
using (var api = new SurveyMonkeyApi("zgSdm04SEefy09ONaxV6b0z5rDOoRHXffGXMAasySfAyxUfCTN4x3AR9IyK5NVoRrBKB27bT-SMlbbL0dI2vUNYQiRNZqbslM0-KATC9JwWblgx4mieUwNxoDzC54lxe"))
{
IEnumerable<Survey> surveys = api.GetSurveyList();
return View(surveys.ToList());
}
}
交换
return View(surveys.ToList());
使用
return View(surveys.Select(s => new SurveyModel(s)));