mvc jquery 修改 viewbag
[HttpGet]
public ActionResult Modify(int id)
{
Books mod=db.Books.Where(b => b.Id == id).FirstOrDefault();
if (mod != null)
{
ViewData["category"] = db.Categories.ToList();
ViewBag.data = db.Publishers.ToList();
return View(mod);
}
return Content("not found");
}
[HttpPost]
public ActionResult Modify(Books mod)
{
HttpPostedFileBase file=Request.Files["File1"];
if(file!=null)
file.SaveAs(Server.MapPath("~/BookCovers/"+mod.ISBN+".jpg"));
Books book=db.Books.Where(b => b.Id == mod.Id).FirstOrDefault();
book.Title = mod.Title;
book.ISBN = mod.ISBN;
db.SaveChanges();
return Redirect("/Book/Index");
}
[HttpGet]
public ActionResult Add()
{
ViewData["category"] = db.Categories.ToList();
ViewBag.data = db.Publishers.ToList();
return View();
}
[HttpPost]
public ActionResult Add(Books mod)
{
HttpPostedFileBase file = Request.Files["File1"];
if (file != null)
file.SaveAs(Server.MapPath("~/BookCovers/" + mod.ISBN + ".jpg"));
mod.PublishDate = DateTime.Now;
db.Books.Add(mod);
db.SaveChanges();
//return Redirect("/Book/Index");
return RedirectToAction("Index");
}
public ActionResult Find()
{
string title = Request.Form["title"];
List<Books> list = null;
if (title != "")
list = db.Books.Where(b => b.Title.Contains(title)).ToList();
else
list = db.Books.Take(10).ToList();
return View("index",list);
}
@{
Layout = null; //add.cshtml
}
@using MvcApplication2.Models
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Add</title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<table style="width:400px; margin:0 auto;" id="tab">
<thead>
<tr>
<th colspan="2" align="center" id="header">添加</th>
</tr>
</thead>
<tbody>
<tr>
<td>标题:</td>
<td>
<input name="Title" id="Title" type="text" />
</td>
</tr>
<tr>
<td>作者:</td>
<td>
<input name="Author" id="Author" type="text" />
</td>
</tr>
<tr>
<td>单价:</td>
<td>
<input name="Price" id="Price" type="text" />
</td>
</tr>
<tr>
<td>出版社:</td>
<td>
<select name="PublisherId">
@foreach (var item in ViewBag.data as List<Publishers>)
{
<option value="@item.pid">@item.pubName</option>
}
</select>
</td>
</tr>
<tr>
<td>类型:</td>
<td>
<select name="CategoryId">
@foreach (var item in ViewData["category"] as List<Categories>)
{
<option value="@item.cid">@item.catName</option>
}
</select>
</td>
</tr>
<tr>
<td>ISBN:</td>
<td>
<input id="ISBN" name="ISBN" type="text" />
</td>
</tr>
<tr>
<td>封面:</td>
<td>
<input id="File1" name="File1" type="file" />
</td>
</tr>
<tr>
<td>点击数:</td>
<td>
<input id="Clicks" value=" 0" name="Clicks" type="text" />
</td>
</tr>
<tr>
<td>出版日期:</td>
<td>
<input id="PublishDate" name="publishdate" type="text" />
</td>
</tr>
<tr>
<td></td>
<td>
<input id="btnOk" type="submit" value="确定" />
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
@{
Layout = null; //modify.cshtml
}
@model MvcApplication2.Models.Books
@using MvcApplication2.Models
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Modify</title>
</head>
<body>
<form action="/Book/Modify" method="post" enctype="multipart/form-data">
<input type="hidden" name="Id" value="@Model.Id" />
<table>
<tr>
<td>标题:</td>
<td><input name="Title" id="Title" value="@Model.Title" type="text" /></td>
</tr>
<tr>
<td>ISBN:</td>
<td><input name="ISBN" id="ISBN" value="@Model.ISBN" type="text" /></td>
</tr>
<tr>
<td>出版社:</td>
<td>
<select name="PublisherId">
@foreach (var item in ViewBag.data as List<Publishers>)
{
if(item.pid==Model.PublisherId){
<option value="@item.pid" selected>@item.pubName</option>
}
else
{
<option value="@item.pid">@item.pubName</option>
}
}
</select>
</td>
</tr>
<tr>
<td>类型:</td>
<td>
<select name="CategoryId">
@foreach (var item in ViewData["category"] as List<Categories>)
{
if (item.cid == Model.CategoryId)
{
<option value="@item.cid" selected>@item.catName</option>
}
else
{
<option value="@item.cid">@item.catName</option>
}
}
</select>
</td>
</tr>
<tr>
<td>封面:</td>
<td>
<input name="File1" type="file" /><br />
@{string img = Model.ISBN + ".jpg";}
<img src="~/BookCovers/@img" width="100" height="150"/>
</td>
</tr>
<tr>
<td></td>
<td><input id="Submit1" type="submit" value="确定" /></td>
</tr>
</table>
</form>
</body>
</html>
@{
Layout = null; //index.cshtml
}
@using MvcApplication2.Models
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script>
function find() {
//location.href = "/Book/Find";
}
</script>
</head>
<body>
<div>
<table>
<tr>
<td>
<form action="/Book/Find" method="post">
按标题查询:<input name="Title" type="text" /><input id="Button1" type="submit" value="查询" />
</form>
</td>
</tr>
</table>
<table>
@foreach (var item in Model as List<Books>)
{
<tr>
<td>@item.Title</td>
<td><a href="/Book/Delete/@item.Id">删除</a></td>
<td><a href="/Book/Modify/@item.Id">修改</a></td>
</tr>
}
</table>
<a href="/Book/Add">添加</a>
</div>
</body>
</html>
mvc jquery 修改 viewbag的更多相关文章
- asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发4- 后台模板html页面创建
上一篇教程<asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发3-登录模块开发>完成了本项目的登录模块,登录后就需要进入后台管理首页了,需要准备一个后台模 ...
- asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发2-Model层建立
上篇(asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发1-准备工作)文章讲解了开发过程中的准备工作,主要创建了项目数据库及项目,本文主要讲解项目M层的实现,M层这里 ...
- ECharts 初识(基于MVC+jQuery+Angularjs实现的Demo)
一.背景: 我们这行做web开发的,很多时候都需要做数据统计报表,现在我所使用的是来自百度团队的ECharts.官方网址:http://echarts.baidu.com/ 我们知 ...
- jQuery修改class属性和CSS样式
jQuery修改class属性和CSS样式 class属性修改 类属性即class属性,规定类名. 用类选择器规定样式的时候,需要为元素指定类名,即class属性的值. 注意每个HTML元素只有一个c ...
- jquery修改css样式,样式带!important
由于需求的需要,今天在用jquery修改一个弹出框的样式的时候,由于有一个按钮有padding-left:12px;导致内间距空出来的这一块颜色用普通的方式无法改变. 普通的jquery修改css的方 ...
- [转]Spring3 MVC + jQuery easyUI 做的ajax版本用户管理
原文地址:http://www.iteye.com/topic/1081739 上周写了篇基于spring3.0.5 mvc 简单用户管理实例 ( http://www.iteye.com/topic ...
- 使用jquery修改css中带有!important的样式属性
当CSS中含有!important的样式属性时,普通的修改方式是会出现失败的.如下: <div class="test">使用jquery修改css中带有!import ...
- jquery修改a标签的href链接和文字
可以先体验一下效果:http://keleyi.com/keleyi/phtml/jquery/2.htm 以下修改a标签的href链接和修改文字的代码: <script type=" ...
- (转载)MVC + JQUERY + AJAX的几种方式
MVC + JQUERY + AJAX的几种方式 // 传过去一个简单值,获取一个简单值 $.ajax({ type: "GET", url: ...
随机推荐
- java数学函数库 API(转)
原文地址:http://www.24xuexi.com/w/2011-11-08/98206.html 首先给大家看看Math类所提供的主要方法,下面的列表给出了Math类的主要方法,如果要理解Mat ...
- JMS确认机制
JMS中为数不多的重点就是消息的确认机制,下面分别介绍J2EE和Spring的MessageListenerContainer的确认机制 J2EE中JMS确认机制 在JMS规范中一共4种确认方式 AU ...
- Redis学习笔记~Redis并发锁机制
回到目录 redis客户端驱动有很多,如ServiceStack.Redis,StackExchange.Redis等等,下面我使用ServiceStack.Redis为例,介绍一下在redis驱动中 ...
- Yii 框架学习--01 框架入门
Yii 是一个高性能的,适用于开发 WEB2.0 应用的 PHP 框架. Yii目前有两个主要的版本: 2.0 和 1.1.本文以YII 2.0.7为例. 环境需求 Yii2.0 框架有一些系统上的需 ...
- Atitit 图像扫描器---基于扫描线
Atitit 图像扫描器---基于扫描线 调用范例 * @throws FileExistEx */ public static void main(String[] args) throws Fil ...
- SlickUpload Quick Start Guide
Quick Start Guide The SlickUpload quick start demonstrates how to install SlickUpload in a new or ex ...
- HTML5横竖屏提示
HTML代码: <div class="screen-prompt"></div> CSS判断代码: /*横竖屏提示*/ @media screen and ...
- 【WP开发】手电筒
或许很多人都想到,可以利用手机上摄像头的闪光灯做手电筒,当然,有利必有害,每次使用的时间不要过长,几分钟一般不会有什么问题,如果时间太长,难保会有损伤. 以往的方案是调用视频录制功能来开始录制视频,同 ...
- 如何用sublime 编写sass
使用了Sublime Text也有一段时日了,然后在现在而言,小觉的coding工具已经非其莫属了,接着小觉因为近期忙着项目的原因,同时还要抽空编辑博客的原因,就暂时把它放在一旁了,现在偶然想起也就说 ...
- CSS三列布局
× 目录 两侧定宽中间自适应 两列定宽一侧自适应 中间定宽两侧自适应一侧定宽两列自适应三列自适应总结 前面的话 前面已经介绍过单列定宽单列自适应和两列自适应的两列布局.本文介绍三列布局,分为两侧定宽中 ...