Moon.Orm在MVC3中应用
配置文件(注意修改 AUTO_COMPLIE_DIRECTORY_PATH 的值为 实际项目的bin路径)
<configuration> <appSettings> <add key="AUTO_COMPLIE_DIRECTORY_PATH" value="E:\Documents and Settings\aa\My Documents\SharpDevelop Projects\Razor.Moon\Razor.Moon\bin\" /> <add key="dbType" value="MSSQL" /> <add key="linkString" value="Server=aa-E15014A6665\SQLEXPRESS;Database=MyNorthwind;uid=sa;Password=123456;" /> </appSettings> </configuration>
数据库
代码
/* * 由SharpDevelop创建。 * 日期: 2013-4-20 * 时间: 9:23 * * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件 */ using System; using System.Web.Mvc; using mynorthdb; using Moon.Orm; namespace Razor.Moon.Controllers { public class HomeController : Controller { public ActionResult Index() { string sql="select OrderDate,Finished from Orders"; var list=DBFactory.GetAutoEntities(sql,"CustomersLeftJoinOrders"); return View(list); } public ActionResult Contact() { Customers data=DBFactory.GetEntity<Customers>(CustomersTable.CustomerID.Equal(1)); return View(data); } void ReturnTextString(Object data) { Response.StatusCode=200; Response.ContentType = "text/plain"; Response.Write(data); Response.End(); } [HttpPost] public void Contact(Customers cus) { cus.SetOnlyMark(CustomersTable.CustomerID.Equal(cus.CustomerID)); DBFactory.Update(cus); ReturnTextString(1); } } }
前端代码
Contact
@model Customers @{ ViewBag.Title = "Contact"; } <script> $(function(){ $("#sub").click(function(){ var data=$("#form1").serialize(); $.post("@Url.Action("Contact","Home")",data,function(data){ alert("修改成功"); }); }); }); </script> <h2>数据更新</h2> @using (Html.BeginForm("Contact","Home",FormMethod.Post,new{@id="form1"})) { <table> <tr><td>CustomerID:</td><td>@Html.TextBoxFor(m=>m.CustomerID)</td></tr> <tr><td>用户名:</td><td>@Html.TextBoxFor(m=>m.CustomerName)</td></tr> <tr><td>用户地址</td><td>@Html.TextBoxFor(m=>m.Address)</td></tr> <tr> <td><input type="button" id="sub" value="submit" /></td></tr> </table> }
Index
@model dynamic @{ ViewBag.Title = "Home"; } <h2>Home</h2> <table> @foreach(var a in Model){ <tr><td>@a.OrderDate</td><td>@a.Finished</td></tr> } </table>
项目及数据库备份文件下载.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!