当前位置: 首页 > news >正文

最容易被收录的网站飞沐视觉北京网站建设公司

最容易被收录的网站,飞沐视觉北京网站建设公司,金华高端网站设计,wordpress 首页链接.NET MVC#xff08;Model-View-Controller#xff09;是微软推出的基于 Model-View-Controller 设计模式的 Web 应用框架#xff0c;属于 ASP.NET Core 的重要组成部分。其核心目标是通过清晰的分层架构实现 高内聚、低耦合 的开发模式#xff0c;适用于构建可扩展的企业级….NET MVCModel-View-Controller是微软推出的基于 Model-View-Controller 设计模式的 Web 应用框架属于 ASP.NET Core 的重要组成部分。其核心目标是通过清晰的分层架构实现 高内聚、低耦合 的开发模式适用于构建可扩展的企业级应用程序。 Model模型层 职责 负责业务逻辑处理、数据访问与验证通常与数据库交互通过 ORM 工具如 Entity Framework。 View视图层 职责 负责用户界面渲染通常使用 Razor 语法.cshtml 文件动态生成 HTML。 Controller控制器层 职责 处理 HTTP 请求、协调 Model 和 View实现业务逻辑的入口。 Model namespace MvcMovie.Models {public class ErrorViewModel{public string? RequestId { get; set; }public bool ShowRequestId !string.IsNullOrEmpty(RequestId);} }using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema;namespace MvcMovie.Models;public class Movie {public int Id { get; set; }[StringLength(60, MinimumLength 3)][Required]public string? Title { get; set; }[Display(Name Release Date)][DataType(DataType.Date)]public DateTime ReleaseDate { get; set; }[Range(1, 100)][DataType(DataType.Currency)][Column(TypeName decimal(18, 2))]public decimal Price { get; set; }[RegularExpression(^[A-Z][a-zA-Z\s]*$)][Required][StringLength(30)]public string? Genre { get; set; }[RegularExpression(^[A-Z][a-zA-Z0-9\s-]*$)][StringLength(5)][Required]public string? Rating { get; set; } } using Microsoft.AspNetCore.Mvc.Rendering;namespace MvcMovie.Models;public class MovieGenreViewModel {public ListMovie? Movies { get; set; }public SelectList? Genres { get; set; }public string? MovieGenre { get; set; }public string? SearchString { get; set; } } using Microsoft.EntityFrameworkCore; using MvcMovie.Data;namespace MvcMovie.Models;public static class SeedData {public static void Initialize(IServiceProvider serviceProvider){using (var context new MvcMovieContext(serviceProvider.GetRequiredServiceDbContextOptionsMvcMovieContext())){// Look for any movies.if (context.Movie.Any()){return; // DB has been seeded}context.Movie.AddRange(new Movie{Title When Harry Met Sally,ReleaseDate DateTime.Parse(1989-2-12).ToUniversalTime(),Genre Romantic Comedy,Rating R,Price 7.99M},new Movie{Title Ghostbusters ,ReleaseDate DateTime.Parse(1984-3-13).ToUniversalTime(),Genre Comedy,Rating R,Price 8.99M},new Movie{Title Ghostbusters 2,ReleaseDate DateTime.Parse(1986-2-23).ToUniversalTime(),Genre Comedy,Rating R,Price 9.99M},new Movie{Title Rio Bravo,ReleaseDate DateTime.Parse(1959-4-15).ToUniversalTime(),Genre Western,Rating R,Price 3.99M});context.SaveChanges();}} } View 部分view代码完整代码在文末获取。 model MvcMovie.Models.Movie{ViewData[Title] Create; }h1Create/h1h4Movie/h4 hr / div classrowdiv classcol-md-4form asp-actionCreatediv asp-validation-summaryModelOnly classtext-danger/divdiv classform-grouplabel asp-forTitle classcontrol-label/labelinput asp-forTitle classform-control /span asp-validation-forTitle classtext-danger/span/divdiv classform-grouplabel asp-forRating classcontrol-label/labelinput asp-forRating classform-control /span asp-validation-forRating classtext-danger/span/divdiv classform-grouplabel asp-forReleaseDate classcontrol-label/labelinput asp-forReleaseDate classform-control /span asp-validation-forReleaseDate classtext-danger/span/divdiv classform-grouplabel asp-forGenre classcontrol-label/labelinput asp-forGenre classform-control /span asp-validation-forGenre classtext-danger/span/divdiv classform-grouplabel asp-forPrice classcontrol-label/labelinput asp-forPrice classform-control /span asp-validation-forPrice classtext-danger/span/divdiv classform-groupinput typesubmit valueCreate classbtn btn-primary //div/form/div /divdiva asp-actionIndexBack to List/a /divsection Scripts {{await Html.RenderPartialAsync(_ValidationScriptsPartial);} }Controller using Microsoft.AspNetCore.Mvc;namespace MvcMovie.Controllers;public class HelloWorldController : Controller {public IActionResult Index(){return View();}public IActionResult Welcome(string name, int numTimes 1){ViewData[Message] Hello name;ViewData[NumTimes] numTimes;return View();} }using Microsoft.AspNetCore.Mvc; using MvcMovie.Models; using System.Diagnostics;namespace MvcMovie.Controllers {public class HomeController : Controller{private readonly ILoggerHomeController _logger;public HomeController(ILoggerHomeController logger){_logger logger;}public IActionResult Index(){return View();}public IActionResult Privacy(){return View();}[ResponseCache(Duration 0, Location ResponseCacheLocation.None, NoStore true)]public IActionResult Error(){return View(new ErrorViewModel { RequestId Activity.Current?.Id ?? HttpContext.TraceIdentifier });}} }using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.EntityFrameworkCore; using MvcMovie.Data; using MvcMovie.Models;namespace MvcMovie.Controllers {public class MoviesController : Controller{private readonly MvcMovieContext _context;public MoviesController(MvcMovieContext context){_context context;}// GET: Moviespublic async TaskIActionResult Index(string movieGenre, string searchString){if (_context.Movie null){return Problem(Entity set MvcMovieContext.Movie is null.);}// Use LINQ to get list of genres.IQueryablestring genreQuery from m in _context.Movieorderby m.Genreselect m.Genre;var movies from m in _context.Movieselect m;if (!string.IsNullOrEmpty(searchString)){movies movies.Where(s s.Title!.ToUpper().Contains(searchString.ToUpper()));}if (!string.IsNullOrEmpty(movieGenre)){movies movies.Where(x x.Genre movieGenre);}var movieGenreVM new MovieGenreViewModel{Genres new SelectList(await genreQuery.Distinct().ToListAsync()),Movies await movies.ToListAsync()};return View(movieGenreVM);}// GET: Movies/Details/5public async TaskIActionResult Details(int? id){if (id null){return NotFound();}var movie await _context.Movie.FirstOrDefaultAsync(m m.Id id);if (movie null){return NotFound();}return View(movie);}// GET: Movies/Createpublic IActionResult Create(){return View();}// POST: Movies/Create// To protect from overposting attacks, enable the specific properties you want to bind to.// For more details, see http://go.microsoft.com/fwlink/?LinkId317598.[HttpPost][ValidateAntiForgeryToken]public async TaskIActionResult Create([Bind(Id,Title,ReleaseDate,Genre,Price,Rating)] Movie movie){if (ModelState.IsValid){movie.ReleaseDate movie.ReleaseDate.ToUniversalTime();_context.Add(movie);await _context.SaveChangesAsync();return RedirectToAction(nameof(Index));}return View(movie);}// GET: Movies/Edit/5public async TaskIActionResult Edit(int? id){if (id null){return NotFound();}var movie await _context.Movie.FindAsync(id);if (movie null){return NotFound();}return View(movie);}// POST: Movies/Edit/5// To protect from overposting attacks, enable the specific properties you want to bind to.// For more details, see http://go.microsoft.com/fwlink/?LinkId317598.[HttpPost][ValidateAntiForgeryToken]public async TaskIActionResult Edit(int id, [Bind(Id,Title,ReleaseDate,Genre,Price,Rating)] Movie movie){if (id ! movie.Id){return NotFound();}if (ModelState.IsValid){try{_context.Update(movie);await _context.SaveChangesAsync();}catch (DbUpdateConcurrencyException){if (!MovieExists(movie.Id)){return NotFound();}else{throw;}}return RedirectToAction(nameof(Index));}return View(movie);}// GET: Movies/Delete/5public async TaskIActionResult Delete(int? id){if (id null){return NotFound();}var movie await _context.Movie.FirstOrDefaultAsync(m m.Id id);if (movie null){return NotFound();}return View(movie);}// POST: Movies/Delete/5[HttpPost, ActionName(Delete)][ValidateAntiForgeryToken]public async TaskIActionResult DeleteConfirmed(int id){var movie await _context.Movie.FindAsync(id);if (movie ! null){_context.Movie.Remove(movie);}await _context.SaveChangesAsync();return RedirectToAction(nameof(Index));}private bool MovieExists(int id){return _context.Movie.Any(e e.Id id);}} }完整代码 https://download.csdn.net/download/XiaoWang_csdn/90418392
http://www.hkea.cn/news/14372395/

相关文章:

  • 玄武模板网站制作品牌一个品牌的策划方案
  • 微网站建设包括哪些免费域名如何建站
  • 手表网站代码网站的建设主机费用
  • 网站建设的风险欧米茄表价格官网报价
  • 微信定制开发 网站开发开发软件公司全部抓进去了
  • 旺旺号查询网站怎么做西宁seo快速排名
  • 郑州做网站设计南城区网站仿做
  • 网站定制论坛百度托管运营哪家好
  • 长沙企业网站制作哪家好男生学什么技术最挣钱
  • 重庆忠县网站建设公司黑马培训是正规学校吗
  • 无锡 网站建设公司制作网页第一件事就是选定一种
  • 青岛网站建设康之迅中国建设银行信用卡黑名单网站
  • 江阴网站建设多少钱论述网站建设的主要内容
  • 企业建设营销网站的目的商城小程序多少钱
  • 阿里云服务器上如何做网站沈阳哪家网站做的好
  • 虹口高端网站建设苏州高端网站建设企业
  • 网站方案模板seo搜索引擎优化到底是什么
  • 凡科做的网站可以在百度搜到吗网站中的文章可以做排名吗
  • 企业门户网站的安全性石家庄企业建站
  • 自己建设网站平台步骤推广软文范文
  • 石家庄做外贸的网站建设简历制作免费模板网站
  • 深圳中小企业网站制作wordpress健身预定主题
  • 怎么看一个网站是不是外包做的基于 wordpress
  • 同服务器网站查询工具常州市城市建设局网站
  • 网站开发与制作工资分类信息发布 wordpress
  • 安徽省校园网站建设icp ip 网站备案查询
  • 黑龙江做网站的公司哪个网站可以做编程题
  • 门户手机网站模板写作网站可以签约未成年吗
  • 手机网站推荐一个互联网设计公司网站
  • 网站关键词做多了是不是影响权重重庆食品公司