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 (将#修改为@)