mvcplayer - Double Content after post-submit

Topics: General, MVC, Troubleshooting
Jun 10, 2011 at 11:22 PM
Edited Jun 10, 2011 at 11:23 PM

Hello Team,

i have a little problem. When is send my data from a razor view, than i have double content (2 formulars). The Model is filled correctly. The method will called 1 time.

Here is my code

The View

 

@Html.ValidationSummary()


<div id="InfoMessage"></div>


@using (Ajax.BeginForm("BookStep1", new AjaxOptions() { UpdateTargetId = "InfoMessage" } ))
{ 

    <br />
    @Html.DropDownListFor(m => Model.LocationStartId, ViewData["from"] as SelectList, " -- please select -- ")
    <br />
    
    @Html.DropDownListFor(m => Model.LocationEndId, ViewData["to"] as SelectList)
    <br />
    @Html.DropDownListFor(m => Model.PersonAmount, ViewData["persons"] as SelectList, " -- please select --")
    <br />

    @Html.TextBoxFor(m => Model.Price)
        
    <input type="submit" value="Weiter" />
    
}

 

 

The GET-Action

 

public ActionResult BookStep1()
    {
        RouteBooking model = new RouteBooking();

        this.SetBookStep1Values();

        return View(model);
    
    }

 

 

The Post Action

 

[HttpPost]
    public ActionResult BookStep1(RouteBooking model)
    {
        

        // try to create the booking
        if (ModelState.IsValid)
        {

            this.SetBookStep1Values();
        return View(model);
        }



        this.SetBookStep1Values();
        return View(model);
    }

 

Any Ideas?

 

 

Thanks a lot.

Developer
Jun 15, 2011 at 12:48 PM

Try close div after Ajax Form

 

<div id="InfoMessage">


@using (Ajax.BeginForm("BookStep1", new AjaxOptions() { UpdateTargetId = "InfoMessage" } ))
{ 

    <br />
    @Html.DropDownListFor(m => Model.LocationStartId, ViewData["from"] as SelectList, " -- please select -- ")
    <br />
    
    @Html.DropDownListFor(m => Model.LocationEndId, ViewData["to"] as SelectList)
    <br />
    @Html.DropDownListFor(m => Model.PersonAmount, ViewData["persons"] as SelectList, " -- please select --")
    <br />

    @Html.TextBoxFor(m => Model.Price)
        
    <input type="submit" value="Weiter" />
    
}
 

</div>
Jun 15, 2011 at 12:49 PM

Hy neex,

this div is only for the message from the ajax result.

regards,

Christian

Developer
Jun 15, 2011 at 1:34 PM

Somthing wrong in @using (Ajax.BeginForm("BookStep1", new AjaxOptions() { UpdateTargetId = "InfoMessage" } ))
this send request to BookStep1 action and insert result into <div id="InfoMessage"></div>, result is form content. so you have dublcated content.

You can write smth like this: 

@using (Ajax.BeginForm("SendForm", new AjaxOptions() { UpdateTargetId = "InfoMessage" } ))

write action 
public string SendForm(RouteBooking model)
    {
       

        // try to create the booking
        if (ModelState.IsValid)
        {

            this.SetBookStep1Values();
        return "Some info message";
        }



        this.SetBookStep1Values();
        return "Some info message 2"
    }