2013-08-18 93 views
1

以下代碼不起作用。剃鬚刀不能正常工作

的控制器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">&times;</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">&times;</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; } 
    } 
} 

我需要做什麼改變嗎?

回答

1

注意對自己和其他人一樣,永遠,永遠真設置HttpMethod屬性,AjaxOptions

+0

是說你定了嗎?如果是這樣,請突出顯示您更改的代碼行並接受您自己的答案。 –