Domanda

I have been trying post a value back to the controller so I can update a balance elsewhere, but I cannot get it to work. I get a message

Error Loading Page

All I want is a double value, but to be honest, I would just like to get the code into the controller in the first instance.

My .cshtml is like:

@using (Html.BeginForm("Deposit", "AccountController", FormMethod.Post))
{
       <fieldset>
        <legend>Deposit Amount</legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.UserName)
        </div>
       <div class="editor-field">
           @Html.TextBoxFor(model => model.UserName)
            @Html.ValidationMessageFor(model => model.UserName)
        </div>
        <p>
            <input type="submit" value="Save" />
        </p>

        </fieldset>

}

And the controller is:

    [HttpGet]
    public ActionResult Deposit()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Deposit(LoginModel model)
    {

        // do things

        return View(model);
    }

I am new to MVC. I know the view code doesn't have the amount value that I ultimately would like to use, or I may add it to a model and just pass that, but I cannot get it to the controller at all.

Thanks in advance.

È stato utile?

Soluzione

I think you're just slightly off on the naming conventions of MVC. Assuming the name of your controller class is AccountController, you should specify that minus the "Controller" part in the BeginForm() method:

@using (Html.BeginForm("Deposit", "Account", FormMethod.Post))
{
    ...
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top