0
Dropdown
dynamic list and database image return does not work after the application is published on IIS. When Inspecting through the browser I had the following error:
HTTP 404.0 error - Not Found (with following request: http://localhost:80/funcio/Concelho/List/1)
for image I had the following through Inspection:
HTTP 404.0 error - Not Found (with following request: http://localhost:80/funcio/Retrieveimage/3
View create :
$(function () {
$("#Ilha").change(function () {
$.getJSON("/funcionario/Concelho/List/" + $("#Ilha > option:selected").attr("value"), function (data) {
var items = "<option>--Selecione--</option>";
$.each(data, function (i, concelho) {
items += '<option value="' + concelho.Value + '">' + concelho.Text + '</option>';
});
$("#Concelho").html(items);
});
});
});
in my routeconfig
created Url:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"SelectConcelho",
url: "Soldado/Concelho/List/{id}",
defaults: new { controller = "Soldado", action = "SelectConcelho", id = "" }
);.....
and in the controller is the method:
[HttpGet]
[Authorize]
public ActionResult SelectConcelho(String id)
{
SITMSEntities conetContext = new SITMSEntities();
int ids;
List<SelectListItem> ConcelhoNome = new List<SelectListItem>();
if (!string.IsNullOrEmpty(id))
{
ids = Convert.ToInt32(id);
List<Concelho> Concelhos = conetContext.Concelho.Where(s => s.Numero_ilha == ids).ToList();
Concelhos.ForEach(s =>
{
ConcelhoNome.Add(new SelectListItem { Text = s.Nome, Value = s.Numero.ToString() });
}
);
}
return Json(ConcelhoNome, JsonRequestBehavior.AllowGet);
}
[Authorize]
public ActionResult RetrieveImage(int id) {
byte[] cover = GetImageFromDataBase(id);
if (cover != null) {
return File(cover, "image/jpg");
} else {
return null;
}
}
and in the view
have:
<img src="/funcionario/RetrieveImage/ @Html.DisplayFor(model => model.Numero)" alt="" height=80 width=80 />
You can enter the code of
RetrieveImage
in your question?– Leonel Sanches da Silva
in the controller:[Authorize] public Actionresult Retrieveimage(int id) { byte[] cover = Getimagefromdatabase(id); if (cover != null) { Return File(cover, "image/jpg"); } Else { Return null; } } and in the view I have:<img src="/funcio/Retrieveimage/ @Html.Displayfor(model => model.Numero)" alt="" height=80 width=80 />
– Evandro barros
Thanks for the help in organizing the Gypsy post. This is my first Post here.
– Evandro barros
Where is the route Default in the
RouteConfig.cs
?– Leonel Sanches da Silva
Maproute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Account", action = "Login", id = Urlparameter.Optional } );
– Evandro barros
in the above url in routeconfig ó corecto e url: "funcio/Concelho/List/{id}", and the controller e funcionaio não soldado
– Evandro barros
You can edit your question by clicking "edit", just below the body of the question. Try. Any doubt, you can call me that I correct for you.
– Leonel Sanches da Silva
Got it Thank you
– Evandro barros
Someone had that problem once.
– Evandro barros