标签:
//第一个参数action名称,第二个参数controller名称 @using (Html.BeginForm("CreateItem", "Knoledge")) { <fieldset> <legend>KnolegeModels</legend> <div class="editor-label"> 标题:<input name="m_strTitle" class="createKnoledge" /> 作者:<input name="m_strUserId" class="createKnoledge" /> 日期:<input class="easyui-datebox" name="m_dateUploadTime" data-options="required:true,showSeconds:false" value="new Date();" style="width: 150px" /> @Html.ActionLink("Back to List", "Index") <input type="submit" value="Create" /> </div> <div class="editor-label"> 描述: </div> <div class="editor-label"> <textarea name="m_strDesc" class="KnoledgeDesc"></textarea> </div> </fieldset> }
//每个参数对应view里input的name public ActionResult CreateItem(string m_strUserId, string m_strTitle, string m_strDesc, string m_dateUploadTime) { //数据库操作,是我自己封装的,可不理会。 Dictionary<string, string> _dictParam = new Dictionary<string, string>(); _dictParam.Add("Id", Guid.NewGuid().ToString()); _dictParam.Add("m_strUserId", m_strUserId); _dictParam.Add("m_strTitle", m_strTitle); _dictParam.Add("m_strDesc", m_strDesc); _dictParam.Add("m_dateUploadTime", m_dateUploadTime); string _strSql = "insert into knoledge(Id,m_strUserId,m_strTitle,m_strDesc,m_dateUploadTime,m_strhot) values(:Id,:m_strUserId,:m_strTitle,:m_strDesc,to_date(:m_dateUploadTime,‘yyyy-MM-dd‘),0)"; int iResult = CommonFunction.OraExecuteNonQuery(_strSql, _dictParam); //跳转的哪个view return View("Create"); }
不太习惯用entity framework 一是感觉原生的sql更可控,二是觉得EF不够通用。(其实是玩的不是很明白啦-_-|||-_-|||)
ASP.NET MVC 个人学习笔记之 View传值到Controller
标签:
原文地址:http://my.oschina.net/u/2004005/blog/413634