如何将选定的下拉列表值从一个视图发送到另一个视图?

时间:2014-08-01 08:27:17

标签: asp.net-mvc

我正在尝试将下拉列表值从一个视图设置为另一个视图。即使两个视图都具有相同的模型,我也没有得到它。

我的第一个观点是,我想从中发送价值

    @using (Html.BeginForm("ApplicantDetails", "Applicant", new { ReturnUrl = ViewBag.ReturnUrl },     FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
    {
        @Html.AntiForgeryToken()

        <section class="form-horizontal">
            <h4>Applicant Detail</h4>
            <hr />
            @Html.ValidationSummary(true)

            <div class="form-group">
                @Html.LabelFor(m => m.Salutation, new { @class = "control-label col-md-2" })
                <div class="col-xs-2 salutation">
                    @Html.DropDownListFor(m => m.Salutation, Model.Salutation, new { @class = "form-control" })
                    @Html.ValidationMessageFor(m => m.Salutation, null, new { @class = "text-warning" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.FirstName, new { @class = "control-label col-md-2" })
                <div class="col-md-3">
                    @Html.TextBoxFor(model => model.FirstName, new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.FirstName,null,new {@class = "text-warning"})
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Surname, new { @class = "control-label col-md-2" })
                <div class="col-md-3">
                    @Html.TextBoxFor(model => model.Surname, new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.Surname, null, new { @class = "text-warning" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.DOB, new { @class = "control-label col-md-2" })
                <div class="col-md-3">
                    @Html.TextBoxFor(model => model.DOB, new {Id = "datepicker", @class = "form-control calender" })
                    @Html.ValidationMessageFor(model => model.DOB, null, new { @class = "text-warning" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Email, new { @class = "control-label col-md-2" })
                <div class="col-md-3">
                    @Html.TextBoxFor(model => model.Email, new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.Email, null, new { @class = "text-warning" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.CountryofResidence, new { @class = "control-label col-md-2" })
                <div class="col-md-3">
                    @Html.TextBoxFor(model => model.CountryofResidence, new { Id = "countryofresidence", @class = "form-control"})
                    @Html.ValidationMessageFor(model => model.CountryofResidence, null, new { @class = "text-warning" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.CountryofNationality, new { @class = "control-label col-md-2" })
                <div class="col-md-3">
                    @Html.TextBoxFor(model => model.CountryofNationality, new { Id = "countryofnationality", @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.CountryofNationality, null, new { @class = "text-warning" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(m => m.Currency, new { @class = "control-label col-md-2" })
                <div class="col-md-2"> 
                    @Html.DropDownListFor(m => m.Currency, Model.Currency, new { @class = "form-control" })
                    @Html.ValidationMessageFor(m => m.Currency, null, new { @class = "text-warning" })
                </div>
            </div>

            <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <input type="submit" value="Go" class="btn btn-primary" />
                    </div>
                </div>
</section>
    }
</div>

我的第二个观点是我想在其中显示值并在称呼TextBox中我想得到第一个观点称呼选择值

<div class="row row-placing">
    @using (Html.BeginForm("Compare", "Quote", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
    {
        @Html.AntiForgeryToken()

        <section class="form-horizontal form-horizontal-placing">
            <div class="form-group table-formgroup">
                <table class="table table-striped table-layout" id="table-dynamic">
                    <thead>
                        <tr class="success">
                            <th>#</th>
                            <th>First Name</th>
                            <th>SurName</th>
                            <th>Date Of Birth</th>
                            <th>Email</th>
                            <th class="table-heading-phone">Phone Number</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr id="row1">
                            <td>
                                <span>1</span> 
                                @Html.TextBox("Salutation", new { @Value = "");
                            </td>
                            <td>
                                @Html.TextBoxFor(m => m.FirstName, new {@Value = Model.FirstName,  @class = "form-control" })
                                @Html.ValidationMessageFor(m => m.FirstName)
                            </td>
                            <td>
                                @Html.TextBoxFor(m => m.Surname, new {@Value = Model.Surname, @class = "form-control " })
                                @Html.ValidationMessageFor(m => m.Surname)
                            </td>
                            <td>
                                @Html.TextBoxFor(m => m.DOB, new {@Value = Model.DOB,  @class = "form-control" })
                                @Html.ValidationMessageFor(m => m.DOB)
                            </td>
                            <td>
                                @Html.TextBoxFor(m => m.Email, new {@Value = Model.Email,  @class = "form-control" })
                                @Html.ValidationMessageFor(m => m.Email)
                            </td>

                            <td>
                                @Html.DropDownListFor(m => m.Extensions, Model.Extensions, "Ext", new { @class = "form-control ext0" })
                                @Html.ValidationMessageFor(m => m.Extensions)
                            </td>
                            <td>
                                @Html.TextBoxFor(m => m.PhoneNumber, new { @class = "form-control phonenumber0" })
                                @Html.ValidationMessageFor(m => m.PhoneNumber)
                            </td>

                        </tr>
                        <tr id="row2"></tr>
                    </tbody>
                </table>
                <div class="depedent">
                    <ul>
                        <li class="col-md-2 ">
                            <label class="control-label">Enter Dependent</label>
                        </li>
                        <li class="col-md-3">
                            <input type="text" name="numberofdependent" class="form-control numberofdepedentextbox " />
                        </li>
                        <li class="col-md-2">
                            <input type="button" name="AddChild" value="Add Dependents" class="btn btn-primary btn-click" />
                        </li>
                        <li class="col-md-2">
                            <input type="button" name="SaveDependent" value="Save Dependents" class="btn btn-primary" />
                        </li>
                    </ul>
                </div>
            </div>
        </section>
    }

提前致谢

1 个答案:

答案 0 :(得分:0)

这一切都在您的帖子中处理并且获取控制器的方法首先发布将接收模型的视图,而不是发回相同的视图或成功的视图等,您可以将其返回到您想要传递的视图模特......但我不确定你想要做什么