分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

MVC控制器返回值

发布时间:2023-09-06 01:35责任编辑:傅花花关键词:MVC
 ?public ActionResult Index(string id)//主页 //参数string searchString 访问方式为index?searchString=xxxx 。参数string id 访问方式为index/x ???????{ ???????????string searchString = id; ???????????????//return View(db.Books.ToList()); //返回一个对象集合 ???????????var s = from m in db.Books select m; //查询所有数据 ???????????????????????if (!string.IsNullOrEmpty(searchString)) //判断传来的数据是否位空 ???????????{ ???????????????s = s.Where(x => x.BookName.Contains(searchString)); //模糊查询数据 ???????????} ???????????return View(s); ???????}
?public ActionResult Edit(int? id) //只能接受整型数据;其他默认null ???????{ ???????????if (id == null) ???????????{ ???????????????return new HttpStatusCodeResult(HttpStatusCode.BadRequest);//传递过去400 //返回400页面 ???????????} ???????????Book book = db.Books.Find(id); //在books表中查找指定id的对象 赋值给Book对象 ???????????if (book == null) ???????????{ ???????????????return HttpNotFound(); //未找到调用HttpNotFound()方法,传递 NotFound = 404,返回404 页面 ???????????} ???????????return View(book); //返回这个对象 ???????}

MVC控制器返回值

原文地址:https://www.cnblogs.com/enych/p/8252773.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved