2017-03-27 2 views
0

Ich habe TeilansichtTeilansicht nicht angezeigt (ASP.NET MVC)

Hier Code ist

@model IEnumerable<SmartSolutions.Models.QuestionBlock> 

@foreach (var item in Model) { 
    <div> 
     @Html.DisplayFor(modelItem => item.Question1) 
    </div>  
} 

Hier Code für die Steuerung

public ActionResult Recording(int id) 
    { 
     /*var items = db.QuestionBlocks 
      .Where(x => x.Interview_Id == id) 
      .Select(x => x).ToList();*/ 
     ApplicationDbContext db = new ApplicationDbContext(); 
     return View(); 
    } 

    public ActionResult QuestionBlock(int id) { 

     ApplicationDbContext db = new ApplicationDbContext(); 
     var questionblocks = db.QuestionBlocks.Take(id); 
     return PartialView(questionblocks); 
    } 

Hier Code of View, wo ich versuche, zu zeigen PartialView

<div class="inner-div4" style="background: #ffffff"> 
<div class="counter-one"> 
    3/10 
</div> 
<div class="right-welcome-div2-borderless" style="background: #e5e5e5"> 
    <div class="timer-div-one" id="countdown" style="height: 20px; width: 20px;"> 

    </div> 
    <div class="counter-div"> 
    </div> 
    <p>@Html.Label("Show", htmlAttributes: new { @class = "showList", @style= "cursor:pointer;", data_rows = 1 })</p> 
    <div id="questions"> 

    </div> 

Hier ist AJAX-Aufruf

<script> 
$('.showList').click(function (e) { 
    var rows_num = this.getAttribute("data-rows"); 
    $.ajax({ 
     type: "GET", 
     url: "/interwier/QuestionBlock", 
     data: { id: rows_num }, 
     sucess: function (data) { 
      $("#questions").html(data); 

     }, 
     error: function() { 
      alert("Smth wrong in controller"); 
     } 
    }); 
}); 

Mein Problem, dass < wenn ich <p>@Html.Label("Show", htmlAttributes: new { @class = "showList", @style= "cursor:pointer;", data_rows = 1 })</p> klicken ich in Netzwerk Konsolendaten zu sehen, aber nicht auf Ansicht zu sehen.

+0

Was ist der Wert davon? 'var questionblocks = db.QuestionBlocks.Take (id);' – mariocatch

+0

Wenn ich den Breakpoint setze, heißt es id = 1 @ mariocatch –

+0

Was ist der Wert von 'questionblocks'? – mariocatch

Antwort

2

Sie haben einen Tippfehler in Ihrem AJAX-Code: sucess statt success. Im Wesentlichen haben Sie im Moment keine success Methode, also passiert nichts mit der zurückgegebenen Antwort.

+0

Flash zurück zur Grundschule Deutsch: "Verdopple das 'C', verdopple das 'S' und du wirst immer * Erfolg *" haben. ;) –

+0

Dies ist nur eines der Probleme. Dies kombiniert mit der anderen Antwort von @Nayan Dhamsaniya ist die tatsächliche Lösung. – mariocatch

+0

lulz, danke. Alle Werke –

1

Ich denke Änderung Parameter Name data_rows zu id. also bitte versuch es.

Und einfache Änderungen in Ihrer Methode.

public ActionResult QuestionBlock(int id) { 

    ApplicationDbContext db = new ApplicationDbContext(); 
    var questionblocks = db.QuestionBlocks.Take(id); 
    return PartialView("Name_Of_PartialView",questionblocks); 
} 
Verwandte Themen