以下代码不起作用。
控制器SupportController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Token.Creator.Site.Models;
namespace Token.Creator.Site.Controllers {
public class SupportController : Controller {
CustomerModel customerModel = new CustomerModel();
public ActionResult Index() {
return View();
}
[HttpGet]
public ActionResult Search(string serialnumber) {
var items = S0PinListModel.GetFromList(customerModel.GetS0Pins(serialnumber));
items.Message = "Es konnten " + items.Count + " gefunden werden :)";
items.Type = MessageType.SuccessMessage;
return PartialView("_S0PinListView", items);
}
}
}
PartialView _S0PinListView.cshtml
@using Token.Creator.Site.Models;
@model S0PinListModel
@if (!string.IsNullOrWhiteSpace(Model.Message)) {
var type = "";
switch (Model.Type) {
case MessageType.ErrorMessage: type = "alert alert-danger";
break;
case MessageType.InfoMessage: type = "alert alert-info";
break;
case MessageType.SuccessMessage: type = "alert alert-success";
break;
case MessageType.WarningMessage: type = "alert";
break;
}
<div id="result" style="display:none;" class="@type fade">
@Model.Message<a class="close" data-dismiss="alert" href="#" aria-hidden="true">×</a>
</div>
<script>
$(".modal").modal('hide');
$("#result").fadeIn("slow").after($(result).addClass('in'));
</script>
}
<table class="table table-condensed">
<thead>
<tr>
<th>#</th>
<th>Seriennummer</th>
<th>S0Pin</th>
<th>Ersteller</th>
</tr>
</thead>
<tbody>
@if (Model != null && Model.Count > 0) {
foreach (var item in Model) {
<tr>
<td>@item.ID</td>
<td>@item.Serialnumber</td>
<td>@item.Pin</td>
<td>@item.Creator.Username</td>
</tr>
}
} else {
<tr class="alert alert-info">
<td colspan="4">Leider sind konnten keine S0Pins gefunden werden :(</td>
</tr>
}
</tbody>
</table>
MainView支持/Index.cshtml
@using Token.Creator.Site.Models;
@{
ViewBag.Title = "Support";
}
<div>
<div class="jumbotron">
<h1>Support</h1>
<p>Suchen Sie nach S0Pins und setzten Sie Token zurück.</p>
<p><a data-toggle="modal" href="#searchmodal" class="btn btn-primary">Nach S0Pins suchen</a></p>
</div>
<div id="szeropindata">
</div>
<div class="modal fade" id="searchmodal" tabindex="-1" role="dialog" aria-hidden="true">
@using (Ajax.BeginForm("Search", "Support", new AjaxOptions() {
UpdateTargetId = "szeropindata",
HttpMethod = "GET" <----- THIS IS IMPORTANT
}, new {
@class = "modal-dialog form-horizontal",
id = "search_szeropin"
})) {
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">S0Pin suchen</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="serialnumber" class="col-lg-3 control-label">Seriennummer</label>
<div class="col-lg-9">
@Html.TextBox("serialnumber", "", new { @class = "form-control", id = "serialnumber" })
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Abbrechen</button>
<input type="submit" class="btn btn-primary" value="Suchen" />
</div>
</div>
}
</div>
</div>
模型S0PinListModel
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Token.Creator.Site.Models {
public class S0PinListModel : List<S0Pin> {
public static S0PinListModel GetFromList(List<S0Pin> s0pinList) {
var list = new S0PinListModel();
list.AddRange(s0pinList);
return list;
}
private S0PinListModel() {
}
public MessageType Type { get; set; }
public string Message { get; set; }
}
}
我需要改变什么?