Dynamic dropdown list and comic return image does not work

Asked

Viewed 138 times

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?

  • 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 />

  • Thanks for the help in organizing the Gypsy post. This is my first Post here.

  • Where is the route Default in the RouteConfig.cs?

  • Maproute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Account", action = "Login", id = Urlparameter.Optional } );

  • in the above url in routeconfig ó corecto e url: "funcio/Concelho/List/{id}", and the controller e funcionaio não soldado

  • 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.

  • Got it Thank you

  • Someone had that problem once.

Show 4 more comments

3 answers

0

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

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

    $.ajax({
        url: strUrl,

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 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);


        }
  • Use "@Url.Action" to format your URL

  • Sorry ai Url for view or routeconfig

  • worked like this: var strUrl = '@Url.Action("Getconcelho", "Funcionario")'; $("#Ilha"). change(Function () { $.getJSON(strUrl +'/'+ ......

0

worked like this:

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


 $("#Ilha").change(function () {
        $.getJSON(strUrl +'/'+ ......

Browser other questions tagged

You are not signed in. Login or sign up in order to post.