Arun Rana
Arun Rana

Reputation: 8606

Load data in Html.BeginForm() section in ASP.NET MVC

I am beginner in MVC3 and building one application, i need to make confirmation page where all details of user will display for confirmation.

I have build wizards to fill this information using javascript & divs and in final wizard i would like to put all details which have been filled by user

 @using (Html.BeginForm("Confirm", "Home", FormMethod.Get))
    {
        <div>
          //user details goes here...
        </div>                      
        <input type="submit" name="name" value="confirm" />
    }

how can i load data here?, i need to make some method call before form will render or something else? please guide me.

thanks in advance.

Upvotes: 1

Views: 2379

Answers (2)

Peter Stegnar
Peter Stegnar

Reputation: 12935

The best way would be to load those data in action that return this page. Load user data into a model object and pass that object to a view:

// Return view
return View( new SomeViewModel(userData));

And than you handle those data in view, like (Razor):

@this.Model.UserFirstName ...

Upvotes: 1

Rafay
Rafay

Reputation: 31043

@using (Html.BeginForm("Confirm", "Home", FormMethod.Get))
    {
        <div id="userDetailDiv">

        </div>                      
        <input type="submit" name="name" value="confirm" />
    }

you can use .load

$(function(){
$("#userDetailDiv").load(@Url.Action('UserDetail'));
}

or you can use RenderAction

@using (Html.BeginForm("Confirm", "Home", FormMethod.Get))
    {
        <div id="userDetailDiv">
                @Html.RenderAction("_UserDetail", "Cintroller");
        </div>                      
        <input type="submit" name="name" value="confirm" />
    }

Upvotes: 0

Related Questions