神华两学一做网站,网站框架是谁做,服务器建站教程,怎样做网站发布信息一、创建movie的视图 二、对cinema、movie视图添加‘添加信息’的操作 一、创建movie的视图 在views文件夹下添加Movie文件夹#xff0c;在这个文件夹下添加Index.cshtml视图#xff0c;为什么添加Index.cshtml这个名字的视图#xff0c;可以看看我们写的MovieController控制… 一、创建movie的视图 二、对cinema、movie视图添加‘添加信息’的操作 一、创建movie的视图 在views文件夹下添加Movie文件夹在这个文件夹下添加Index.cshtml视图为什么添加Index.cshtml这个名字的视图可以看看我们写的MovieController控制器 using DemoCoreStudy.Models
model IEnumerableMoviediv classcontainerdiv classrowtable classtablethead classthead-darktrth scopecolId/thth scopecolName/thth scopecolStaring/thth scopecolReleseDate/thth/th/tr/theadtbodyHtml.DisplayForModel()/tbody/table/div
/div 然后再Movie文件夹下添加DispalyTemplates文件夹其中添加Movie.cshtml视图 model DemoCoreStudy.Models.Movietrth scopecolModel.Id/thtdModel.Name/tdtdModel.Starring/tdtdModel.ReleseDate/tdtd asp-actionEdit asp-route-movieIdModel.Id编辑/td
/tr 接下来回到MovieController控制器添加Edit方法 public IActionResult Edit(int movieId){return RedirectToAction(Index);}然后我们回到Cinema.cshtml写下一个跳转链接点一下电影名可以跳转到对应的的电影界面 model DemoCoreStudy.Models.Cinema Model.Id Model.Name Model.Location Model.Capacity 编辑 就插了一行现在运行可以完美运行 QWQ 开心 二、对cinema、movie视图添加‘添加信息’的操作 接下来就是对信息添加功能的操作了 先对cinema进行添加操作 我们需要有个添加的按钮 打开cinema视图的index添加 model IEnumerableDemoCoreStudy.Models.Cinemadiv classcontainerdiv classrowtable classtablethead classthead-darktrth scopecolId/thth scopecolName/thth scopecolLocation/thth scopecolCapacity/thth/th/tr/theadtbodyHtml.DisplayForModel()/tbody/tablea asp-actionAdd添加/a/div
/div接下来建立Add.cshtml 打开bootstrap官网左边菜单 Components-Forms 下面是官方原本的代码 formdiv classform-group rowlabel forstaticEmail classcol-sm-2 col-form-labelEmail/labeldiv classcol-sm-10input typetext readonly classform-control-plaintext idstaticEmail valueemailexample.com/div/divdiv classform-group rowlabel forinputPassword classcol-sm-2 col-form-labelPassword/labeldiv classcol-sm-10input typepassword classform-control idinputPassword placeholderPassword/div/div
/form根据官方给出的文档修改下再Home文件夹下建立Add.cshtml Add.cshtml model DemoCoreStudy.Models.Cinemadiv classcontainerform asp-actionAdddiv classform-group rowlabel asp-forName classcol-sm-2 col-form-label电影名称/labeldiv classcol-sm-10input typetext classform-control asp-forName //div/divdiv classform-group rowlabel asp-forLocation classcol-sm-2 col-form-label地点/labeldiv classcol-sm-10input typetext classform-control asp-forLocation //div/divdiv classform-group rowlabel asp-forCapacity classcol-sm-2 col-form-label容纳多少观众/labeldiv classcol-sm-10input typetext classform-control asp-forCapacity //div/divdiv classform-group rowdiv classcol-sm-10 offset-sm-2button typesubmit classbtn btn-primarySubmit/button/div/div/form
/div来运行下吧 啊哈哈哈搞定了对于movie的添加原理相同不同的是你要添加到那个电影院的Id名头下 在movie文件夹下的Index添加按钮 using DemoCoreStudy.Models
model IEnumerableMoviediv classcontainerdiv classrowtable classtablethead classthead-darktrth scopecolId/thth scopecolName/thth scopecolStaring/thth scopecolReleseDate/thth/th/tr/theadtbodyHtml.DisplayForModel()/tbody/tablea asp-actionAdd asp-route-cinemaIdViewBag.cinemaId添加/a/div
/div asp-route-cinemaIdViewBag.cinemaId这句话意思为要返回一个对应cinemaId的值将电影数据加入对应的电影院之下 在movie文件夹下添加Add.cshtml视图 model DemoCoreStudy.Models.Moviediv classcontainerform asp-actionAddinput typehidden asp-forCinemaId /!--隐藏返回的Id属性--div classform-group rowlabel asp-forName classcol-sm-2 col-form-label电影名称/labeldiv classcol-sm-10input typetext classform-control asp-forName //div/divdiv classform-group rowlabel asp-forStarring classcol-sm-2 col-form-label主演/labeldiv classcol-sm-10input typetext classform-control asp-forStarring //div/divdiv classform-group rowlabel asp-forReleseDate classcol-sm-2 col-form-label上映时间/labeldiv classcol-sm-10input typedate classform-control asp-forReleseDate //div/divdiv classform-group rowdiv classcol-sm-10 offset-sm-2button typesubmit classbtn btn-primarySubmit/button/div/div/form
/div 这两个地方出现了问题改下 第一张图的问题就不解释了 第二张图 我们的Add.cshtml中需要得到cinemaId所以要添加ViewBag.CinemaId cinemaId; 告诉它应该放入那个电影院中 已经可以了 github源码https://github.com/1045683477/.net-Core-MVC- 转载于:https://www.cnblogs.com/zuiren/p/10849926.html