微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MVC下拉列表onchange,页面更改

如何解决MVC下拉列表onchange,页面更改

我有一个asp.net MVC应用程序。有一个包含4个选项的下拉列表。下拉列表中的选项是 Book DVD 参考书有声读物。我的想法是我希望能够创建其他类型(书籍,DVD 等)

我想做的是 ,例如,当我从下拉菜单中选择 Book 时,我想查看特定的 Index.cshtml 。而且,当我选择 DVD 时,我希望能够看到放置在该特定类型上的值。

代码Create.cshtml (我不确定是否在此处放置“解决方代码”。请不要告诉我。)

  @model Library.LibraryItem

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>


@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <h4>LibraryItem</h4>
        <hr />
        @Html.ValidationSummary(true,"",new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.Id,htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Id,new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Id,new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.CategoryId,"CategoryName",htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("CategoryId",null,htmlAttributes: new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.CategoryId,new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Title,htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Title,new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Title,new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Author,htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Author,new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Author,new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Pages,htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Pages,new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Pages,new { @class = "text-danger" })
            </div>
        </div>

        @*<div class="form-group">
            @Html.LabelFor(model => model.RunTimeMinutes,htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.RunTimeMinutes,new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.RunTimeMinutes,new { @class = "text-danger" })
            </div>
        </div>*@

        <div class="form-group">
            @Html.LabelFor(model => model.IsBorrowable,htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <div class="checkBox">
                    @Html.EditorFor(model => model.IsBorrowable)
                    @Html.ValidationMessageFor(model => model.IsBorrowable,new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Borrower,htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Borrower,new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Borrower,new { @class = "text-danger" })
            </div>
        </div>

        @*<div class="form-group">
            @Html.LabelFor(model => model.BorrowDate,htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.BorrowDate,new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.BorrowDate,new { @class = "text-danger" })
            </div>
        </div>*@

        <div class="form-group">
            @Html.LabelFor(model => model.Type,htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Type,new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Type,new { @class = "text-danger" })
            </div>
        </div>

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

    <div>
        @Html.ActionLink("Back to List","Index")
    </div>
    
    @section Scripts {
        @Scripts.Render("~/bundles/jqueryval")
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。