MVC 个人总结
来源:互联网 发布:手机淘宝返利怎么返利 编辑:程序博客网 时间:2024/06/06 08:37
1.<a href="@Url.Action(".....")">跳转至对应的Controller的Action方法所指向的页面。
如果Action方法存在参数,则<a href="@Url.Action("方法名称",new {id=@model.id...})"
2.button方法按下后执行方法:
@using (Html.BeginForm("PostTable", "Table1", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{}
3.获取页面中的textbox中的值:
@Html.TextBoxFor(model => model.name, new { @class = "col-xs-10 col-sm-5" })
@Html.ValidationMessageFor(model => model.name)
4.Controller
namespace 1.Controllers
{
[Authorize]
public class Table1Controller : Controller
{
private Table1Service _Table1Serivce= new Table1Service();
private ApplicationUserManager _userManager;
public Table1Controller()
{
ServiceFactory<Table1Service>.Current.Create(_Table1Serivce);
}
public ApplicationUserManager UserManager
{
get
{
return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
private set
{
_userManager = value;
}
}
// GET: Table1
public ActionResult Index()//查询
{
var list= _Table1Serivce.GetAllTable1();
var table1 = new List<Table1Model>();
Table1ListModel model = new Table1ListModel();
foreach(var tb in list)
{
table1.Add(new Table1Model
{
Id=tb.Id,
name = tb.name,
});
}
model = new Table1ListModel { tablelist = table1 };
return View(model);
}
public ActionResult Deletetable(int id)//删除
{
var tb = _Table1Serivce.Gettable1ById(id);
_Table1Serivce.DeleteTable1(tb);
return RedirectToAction("Index");
}
public ActionResult ViewTable(int id)//显示某个信息
{
if (id > 0)
{
}
var table = _Table1Serivce.Gettable1ById(id);
var model = new Table1Model
{
Id=table.Id,
name=table.name,
};
return View(model);
}
public ActionResult NewTable()//打开新增页面
{
var model = new Table1Model();
return View(model);
}
public ActionResult ViewUpdate(int id)//打开修改页面
{
var table = _Table1Serivce.Gettable1ById(id);
var model = new Table1Model
{
Id = table.Id,
name = table.name,
};
return View(model);
}
[HttpPost]
public ActionResult PostTable(Table1Model model)//新增
{
if (ModelState.IsValid)
{
try
{
int Id = model.Id;
string name=model.name;
var table1 = new Table1
{
Id = Id,
name = name,
};
_Table1Serivce.InsertTable1(table1);
return RedirectToAction("Index");
}
catch (Exception ex)
{
ModelState.AddModelError("", ex.Message);
}
}
return RedirectToAction("Index");
}
[HttpPost]
public ActionResult UpdateTable(Table1Model model)//修改
{
var table1 = _Table1Serivce.Gettable1ById(model.Id);
table1.name = model.name;
_Table1Serivce.UpdateTable1(table1);
return RedirectToAction("Index");
}
}
}
- MVC 个人总结
- MVC 与 SSH(个人总结)
- 浅析spring mvc和struts2的区别及个人总结
- MVC之个人理解
- MVC的个人理解
- MVC的个人理解
- MVC个人理解
- MVC个人总计大全
- 个人总结
- 个人总结
- 个人总结
- 个人总结
- 个人总结.
- 个人总结
- 个人总结
- 个人总结
- 个人总结
- 个人总结
- SQL语句整理
- ArrayList中元素排序方法:Collections.sort(list)
- JDK源代码阅读之CharSequence
- Android中将布局文件/View添加至窗口过程分析 ---- 从setContentView()谈起
- AVAudioSession
- MVC 个人总结
- 51nod 1022 石子归并 环形+四边形优化
- Pods written in Swift can only be integrated as frameworks
- POJ-2960(S-Nim)——博弈论,SG函数
- SAP起停异常—实例仍然运行但SAP起停脚本检测不到
- log4j的使用
- Linux signal 那些事儿 (3)
- nasm : 搭建可用的裸机U盘环境
- 详解Android中AsyncTask的使用