Reputation: 61
I am new in asp.net-MVC and it's my first MVC app.
I have a controller linked to a partial view : (_UtilisateurController.cs) :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Mvc_LanceurBatch.BLL;
using Mvc_LanceurBatch.DTO;
using System.ComponentModel.DataAnnotations;
using System.Web.ModelBinding;
namespace Mvc_LanceurBatch.Controllers
{
public class _UtilisateurController : Controller
{
LanceurBatchDLL _oLanceurBatchDLL = new LanceurBatchDLL();
public ActionResult Utilisateur()
{
List<UtilisateurDTO> oListUtilisateur = _oLanceurBatchDLL.GetUtilisateur("", "").ToList();
return View(oListUtilisateur);
}
}
}
Partial view (_Utilisateur.cshtml) :
@using Mvc_LanceurBatch.D TO
@model Mvc_LanceurBatch.DTO.UtilisateurDTO
<div class="col-md-10">
@Html.DropDownListFor(u => u.LI_LOGIN, new SelectList(Model.Utilisateurs, "LI_LOGIN", "NOM"), "Sélectionner un utilisateur")
<input id="ButtonReinit" type="Button" value="Réinitialiser" />
</div>
<script>
$(document).ready(function () {
$("#LI_LOGIN").change(function (e) {
$.ajax({
type: 'get',
url: '@Url.Action("RechercheDemande")',
contentType: 'application/json; charset=utf-8',
dataType: 'html',
data: { "Login": $(this).val() },
success: function (result) {
$("#divDemande").html(result);
},
error: function (ex) {
alert("Error");
}
});
});
});
</script>
And my main view (LanceurBatch.cshtml) :
@{
ViewBag.Title = "Lanceur de batch";
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>
@*@@using (Html.BeginForm("RechercheDemande", "LanceurBatch", FormMethod.Post))*@
@using (Ajax.BeginForm("RechercheDemande", "LanceurBatch", new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
UpdateTargetId = "divPartial",
}))
{
<div class="col-md-10">
@Html.Action("Utilisateur", "Mvc_LanceurBatch.Controllers._UtilisateurController")
<br/>
<br />
<div class="col-lg-12 col-md-12 col-xs-12" id="divPartial">
<label></label>
@Html.Action("RechercheDemande")
</div>
</div>
}
When I run the app, my main view (LanceurBatch.cshtml) fails at the line: @Html.Action("Utilisateur",...
The error is:
The controller for the path « /LanceurBatch/LanceurBatch » cannot be found or doesn't implement IController.
Can someone tell me what's wrong?
Upvotes: 0
Views: 369
Reputation: 61
I have found what's wrong. I have renamed the view and the controller without underscores. In the view LanceurBatch.cshtml I have modified :
@Html.Action("Utilisateur", "Utilisateur")
In the controller UtilisateurController.cs :
return PartialView("~/Views/LanceurBatch/Utilisateur.cshtml", oUtilisateur);
And I have removed from the LanceurBatch.cshtml:
@Html.Action("RechercheDemande")
Upvotes: 1