0

I have

public PartialViewResult CodePartial(string code){
     ...
     return PartialView("anotherpartial");
}  

which on has submit button and I want that on post executed anotherpartial partialviewresult. but instead it returns this partial view inside of CodePartial view. And on debugging it's not going inside of anotherpartial action. How can I improve that?

CodePartial.cshtml

@model Kubeti.Models.Codes



@using (Ajax.BeginForm("CodePartial", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "result", InsertionMode = InsertionMode.Replace }))
{
  @Html.EditorFor(x => x.code)
  @Html.ValidationMessageFor(x => x.code)

  <input type="submit" value="OK" />
}

<div id="result" style="width: 500px; height:500px; border:1px solid red;">

index.cshtml

@Html.Partial("CodePartial")
@Html.Partial("anotherpartial")

enter image description here

gsiradze
  • 4,583
  • 15
  • 64
  • 111

1 Answers1

0

Your method:

public PartialViewResult CodePartial(string code){
     ...
     return PartialView("anotherpartial");
}

doesn't return 'to an action' as such. It simply returns the PartialView representation (meaning without the view being rendered with the layout, amongst other things) of the view that you specify.

If you want to return to another action, you need to post to that action or, alternatively, do something like this.

Community
  • 1
  • 1
Inspector Squirrel
  • 2,548
  • 2
  • 27
  • 38