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>

项目及数据库备份文件下载.

点此下载

posted @ 2013-05-13 17:34  [秦时明月]  阅读(752)  评论(5编辑  收藏  举报