Question

I want this:

@using (Html.BeginForm("bgcTest", "CompaniesController")) 
{
    <p>
        Ange BolagsID: <br />
        <input type="text" name="BolagsID" />
        <input type="submit" value="bgc test" />
    </p>
}

To fire this event:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult bgcTest(string BolagsID)
{
     ...
}

But I get the error:

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /CompaniesController/bgcTest

I can't for the life of me figure it out. If I just make an actionlink I get my method to fire, but I need an user inputted variable to go along with the fireing.

What am I doing wrong?

(This is my first time with MVC and I have to implement some functionality into an already existing project. For work.)

Was it helpful?

Solution

The name of your controller class (.cs file) is CompaniesController.cs. That's a convention (default behavior) where MVC will automatically identify it as a controller. When referencing this controller in your view, use Companies only. If you use CompaniesController MVC will try to find a CS file named CompaniesControllerController.

Correct code:

@using (Html.BeginForm("bgcTest", "Companies"))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top