dynamic dropdown list and bd image return does not work

0

Dropdown dynamic list and database image return does not work after the application is published in IIS. When I inspected through the browser I had the following error:

  

HTTP Error 404.0 - Not Found (with following request: link )

For image I had the following through Inspection:

  

HTTP Error 404.0 - Not Found (with following request: link

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 I 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 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 view I have:

<img src="/funcionario/RetrieveImage/ @Html.DisplayFor(model => model.Numero)" alt="" height=80 width=80 />
    
asked by anonymous 27.08.2015 / 18:13

3 answers

0

If after publication you are giving Page not found. This may be the path to the request you are using. Try to mount the url like this:

        var strUrl = '@Url.Action("ConsultarRegiosPorPrestador", "TabelaFrete")';

    $.ajax({
        url: strUrl,
    
27.08.2015 / 18:26
0

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 I created Url:

    public static void RegisterRoutes(RouteCollection routes)
    {

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
         "SelectConcelho",
         url: "funcionario/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);


        }
    
27.08.2015 / 18:39
0

It worked like this:

var strUrl = '@Url.Action("GetConcelho", "Funcionario")';  


 $("#Ilha").change(function () {
        $.getJSON(strUrl +'/'+ ......
    
31.08.2015 / 13:35