Scénario: J'ai une liste déroulante, un bouton et une table html qui affiche les données du modèle. Voici le code dans le contrôleur ASPX &mvc retour partiel lorsque le bouton est cliqué en utilisant ajax
Les données sont affichées sans postback quand je clique sur le bouton Envoyer, mais dropdownlist bouton & apparaît deux fois, puis les clics suivants sont très bien.
Dois-je utiliser Html.RenderPartial n'importe où, pas sûr ???
//Controller
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SimpleUpdate(int carMake)
{
ViewData["CarMake"] = new SelectList(_carDataContext.Makes.Select(m => new { ID = m.Id, Name = m.Name }), "ID", "Name", carMake);
var carModel = _carDataContext.Models.Where(m => m.MakeId == carMake).ToList();
return PartialView("carmodels", carModel);
}
// in aspx
<%using (Ajax.BeginForm("SimpleUpdate", new AjaxOptions { UpdateTargetId = "ajaxPanel" }))
{%>
<%=Html.DropDownList("CarMake")%>
<br />
<input type="submit" value="SimpleUpdate" />
<%
}%>
<div id="ajaxPanel">
<%
if (Model != null)
{
%>
<table>
<tr>
<th>
Id
</th>
<th>
Name
</th>
<th>
MakeId
</th>
</tr>
<%
foreach (var item in Model)
{%>
<tr>
<td>
<%=Html.Encode(item.Id)%>
</td>
<td>
<%=Html.Encode(item.Name)%>
</td>
<td>
<%=Html.Encode(item.MakeId)%>
</td>
</tr>
<%
}%>
</table>
<%}%>
</div>