5

I have a page that calls another partial view. The page loads fine, but when there is a validation error, it appears to call the post method multiple times.

The code that is causing the issue is here:

<div>
    @{Html.RenderAction("ViewUploadedDocs", "TrackingHome", new { number = @Model.Id.ToString() });}
</div>

This should call the following method in the controller.

    public ActionResult ViewUploadedDocs(string number)
    {
        return PartialView();
    }

It is not decorated with [HttpGet] or [HttpPost]. The method that keeps getting called is below which is the post method of the page.

    [HttpPost]
    [MultipleButton(Name = "action", Argument = "Save")]
    public ActionResult Edit(EditScreenModelValidation model)
    {
        if (ModelState.IsValid)
        {
            return RedirectToAction("UserWorkflows", "Home", new { Area = "Workflow" });
        }
        return View("Edit", model);
    }

I have read on stackoverflow where people have the page calling the post method that they are trying to get, but mine is calling the post method of my main page and not the page that I am trying to get. If I remove the renderAction line in my main page, then the page works correctly, and the action does not call the Edit page in it.

Nate
  • 761
  • 1
  • 8
  • 27
  • 5
    There isn't enough information in the question to debug this. – Liam Apr 25 '16 at 14:07
  • 1
    What other information would you like to see? – Nate Apr 25 '16 at 15:06
  • 2
    I'm not sure.... and that's a problem. This feels like something that only you and the people with full access to your code can solve. this is likely why you have few views, no answers and no comments (apart form mine). Sorry – Liam Apr 25 '16 at 15:09
  • did you try Html.Renderpartial or html.partial ? – Rajdeep Apr 26 '16 at 08:48
  • 2
    It could help if you have a minimalistic reproduction of the issue, that could be completely posted. Also it seems that it might be a problem of routing? So your controller and routes could help solving the issue. – Petr Vávro Apr 27 '16 at 07:13
  • kind of similar have a look http://stackoverflow.com/questions/2751138/mvc-controller-is-being-called-twice – Mohammed Dawood Ansari May 01 '16 at 10:08

1 Answers1

0

RenderAction invokes the specified child action method and renders the result inline in the parent view (it calls the action). You should use RenderPartial if you need to pass the current ViewDataDictionary object or Partial if you need the specified view to be rendered as an HTML-encoded string, depending on what you're trying to accomplish.

crosstec
  • 302
  • 3
  • 9