ASP.NET MVC looking for wrong action(without parametrs)

87 views Asked by At

I want to create an edits views, all for one big model in table, but there will be smaller models" for Basic Informations, Contact Informations etc, my model Table is really big and I don't want to create one edit view with 20 textboxes.

So here is problem I create HttpGet Action with parametr id, and HttpPost with model. And when I'm sending my form I got error System.MissingMethodException, I dont have Action method without parametrs..

Kontrahenci is my model from EF for table. DaneOglneKontrahenta is assistant class, to send only 6 variables instead of 20.

[HttpGet]
public ActionResult EdytujDaneOgolne(int? id)
{

    if (id == null)
    {
        Redirect("Index");
    }

    Kontrahenci kontrahent = db.Kontrahenci.Find(id);

    if (kontrahent == null)
    {
        Redirect("Index");
    }

    DaneOglneKontrahenta model = new DaneOglneKontrahenta(kontrahent);

    return View(model);
}

Post method:

[HttpPost]
public ActionResult EdytujDaneOgolne(int id, DaneOglneKontrahenta kontrahent)
{

    Kontrahenci kontrahentModel = db.Kontrahenci.Find(id);

    if (kontrahentModel == null)
    {
        Redirect("Index");
    }

    kontrahentModel.Nazwa = kontrahent.Nazwa;
    kontrahentModel.NazwaSkrocona = kontrahent.NazwaSkrocona;
    kontrahentModel.NIP = kontrahent.NIP;
    kontrahentModel.Komentarz = kontrahent.Komentarz;
    kontrahentModel.UwagiDS = kontrahent.UwagiDS;
    kontrahentModel.UwagiZlecenie = kontrahent.UwagiZlecenie;

    db.SaveChanges();

    return View("Detalis");
}

Then in View:

@using(Html.BeginForm())
{
 //Some textboxes 
 <input type="submit" value="Create" class="btn btn-default" />
}
1

There are 1 answers

2
moath naji On

you just need to specify the controller name and action in the Begin form method

@using(Html.BeginForm("ActionName","ControllerName",FormMethod.Get)) // Get or Post
{
 //Some textboxes 
 <input type="submit" value="Create" class="btn btn-default" />
}