HTTP Error 404.0 Not Found

0

Good day mates I have this code of the contrlador and the view in asp.net mvc but when clicking on edit I get this error and verify to have created the view, I think it does not identify by id but in my code in the controller what I put it to go by id.

  

HTTP Error 404.0 Not Found The resource you are looking for has been removed,   the name has been changed or is not available at this time

     

Requested URL: localhost: xxx / test / edit / 3

code in the controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using proyecto.Models;

namespace proyecto.Controllers
{
    public class testController : Controller
    {
        private TestStatusyEntities db = new TestStatusyEntities();
        // GET: test
        public ActionResult Index()
        {
            return View(db.testmostrar().ToList());
        }

        // GET: test/Details/5
        public ActionResult Details(double id)
        {
            return View();
        }

        // GET: test/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: test/Create
        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

public Action Result Edit(double id)
    {
        prueba usr = db.selectid(id).First();
        return View(usr);
    }

    [HttpPost]
    public Action Result Edit(double id, FormCollection collection)
    {
        try
        {
            prueba usr = db.selectid(id).First();
            if(ModelState.IsValid)
            {
                db.spactualizar(id, collection["encargado"],collection["estado"],collection["material"]);
            }
            return RedirectToAction("Index");
        }
        catch
        {
            return View();
        }

    }

Vista

    @model proyecto.Models.prueba
    @{
        ViewBag.Title ="Edit";
    }

    <h2>Edit</h2>

    @using (Html.BeginForm())
    {
        <fieldset>
            <div class="editor-label">
                @Html.LabelFor(model => model.encargado)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.encargado)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.estado)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.estado)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.material)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.material)
            </div>
            <p>
                <input type="submit" value="guardar"/>
            </p>

        </fieldset>
    }

<div>
    @Html.ActionLink("regresar", "Index")
</div>
    
asked by senseilex 28.06.2017 в 00:16
source

3 answers

0

The class is testController and the URL that is giving you the error is /prueba/edit/3 ; what you need to change in the address that " prueba " by the name of your controller without the suffix Controller , in this case " test ":

  

localhost: xxx / test / edit / 3

The only thing you have to do is change the address in each link from where you are trying to reach, which in your case should be in your view Index of the folder /Views/test .

    
answered by 30.06.2017 / 00:18
source
1

Clarifications:

Are you sure you compile "Action Result"? It should be a single word.

From the following code, you have a comma that generates another problem.

public Action Result Edit(double id,)
{
    prueba usr = db.selectid(id).First();
    return View(usr);
}

Add your routes that you have defined in the Global.asax, something like this:

public static void RegisterRoutes(RouteCollection routes)
{
  routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );
}
    
answered by 28.06.2017 в 01:11
1

The route should be

  

localhost: xxx / test / edit / 3

By default, the name of the class is taken by removing the Controller suffix

    
answered by 28.06.2017 в 06:15