简体   繁体   English

在ASP.NET MVC的Html.BeginForm()部分中加载数据

[英]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. 我是MVC3的新手,正在构建一个应用程序,我需要创建确认页面,其中将显示用户的所有详细信息以进行确认。

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 我有构建向导来使用javascript和div填充此信息,在最终向导中,我想放置用户已填写的所有详细信息

 @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. 提前致谢。

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): 然后,您可以在视图中处理这些数据,例如(Razor):

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

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

you can use .load 你可以使用.load

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

or you can use RenderAction 或者您可以使用RenderAction

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM