MVC基架生成的Create视图

@model MyMusicStore.Models.Album

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>


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

        <div class="form-group">
            @Html.LabelFor(model => model.ArtistId, "ArtistId", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("ArtistId", null, htmlAttributes: new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.ArtistId, "", 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.Price, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Price, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Price, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.AlbumArtUrl, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.AlbumArtUrl, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.AlbumArtUrl, "", 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")
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ASP.NET MVC CRUD是指在ASP.NET MVC框架中进行创建(Create)、读取(Read)、更新(Update)和删除(Delete)操作的一种常见模式。在ASP.NET MVC中,可以使用控制器和视图来实现这些操作。 在创建(Create)操作中,可以使用控制器的POST方法来接收用户输入的数据,并将其保存到数据库中。通常,可以在视图中使用表单来收集用户输入的数据,并将其提交到控制器的POST方法中进行处理。引用[3]中的代码片段展示了一个基本的表单,其中使用了基架系统(Scaffolding System)生成的<label>和<input>元素。 在读取(Read)操作中,可以使用控制器的GET方法来从数据库中检索数据,并将其传递给视图进行显示。引用[1]中的代码片段展示了如何在视图中使用强类型的Model对象来遍历User列表,并使用foreach语句生成相应的HTML元素。 在更新(Update)操作中,可以使用控制器的POST方法来接收用户输入的更新数据,并将其保存到数据库中。通常,可以在视图中使用表单来显示要更新的数据,并将其提交到控制器的POST方法中进行处理。 在删除(Delete)操作中,可以使用控制器的POST方法或GET方法来删除数据库中的数据。通常,可以在视图中使用链接或按钮来触发删除操作,并将其提交到控制器的相应方法中进行处理。 总之,ASP.NET MVC CRUD模式提供了一种结构化的方式来管理数据的创建、读取、更新和删除操作,使开发人员能够更轻松地构建和维护应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值