MVC 表单问题 项目是采用mvc做的 这个页面有两个form,当我点击一个form里面的submit时,提交到服务器后有一个返回值,然后把返回值赋给隐藏控件,然后点击另一个form时把这个值和form里面的数据一起插入数据库,但是我不知道怎么弄,大家能后提醒一下。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用2个表单 用不同的名字,第一个表单获取获取回数据,用一个通过ViewData传给第二个表单的隐藏控件,然后提交第2个表单,就可以了 关键是把viewData传给第二个表单不知道怎么弄了。 这是第一个表单,用Viewdata保存数据,页面要刷新就没了 public ActionResult addFile(FormCollection formvalues) { try { StringBuilder sb = new StringBuilder(""); foreach (string item in Request.Files) { HttpPostedFileBase file = Request.Files[item] as HttpPostedFileBase; if (file == null && file.ContentLength == 0) continue; string path = Server.MapPath("~//UploadFile//");//上传的路径 if (!System.IO.Directory.Exists(path)) //如果不存在该路径,则创建 { System.IO.Directory.CreateDirectory(path); } path = AppDomain.CurrentDomain.BaseDirectory + "UploadFile/"; string fileName = Path.GetFileName(file.FileName); string tempFileName = fileName.Substring(0, fileName.IndexOf('.')) + DateTime.Now.ToString("yyyyMMddHHmmss") + fileName.Substring(fileName.IndexOf('.'), fileName.Length - (fileName.IndexOf('.'))); file.SaveAs(Path.Combine(path, tempFileName)); //上传文件 Pub_Attachment att = new Pub_Attachment(); att.FileName = fileName; att.FilePath = Path.Combine(path, tempFileName); att.FileContext = ""; att.Status = "1"; att.Re = ""; //att.CreateBy=Session att.CreateDate = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); attService.Insert(att); //返回上传文件的ID string tempID = (attService.Select(" and FilePath='" + att.FilePath + "' ")).SingleOrDefault().AttachmentID; sb.Append(tempID + "|"); } ViewData["File"] = sb; return RedirectToAction("Doc_Model1_Add"); //return Content("<script>alert('上传文件成功');window.history.back();</script>"); } catch (Exception ex) { log.Error(ex.Message, ex); return Redirect(Request.ApplicationPath + "error.htm"); } 用页面传值,把viewstate中的数据传给form2 ,然后form2提交的时候保存到数据库中。 但是我不知道怎么弄了,我提交form1,上传到服务器,页面会刷新。 2个表有相同字段,如何指定 如何判断这个字符 sessionState mode="SQLServer"...........的问题 绑定datatable 验证码问题.. 请教几个关于DataGrid控件的问题~~~ 请教一个文件下载的问题!!! 最后20分!有关SQL查询的,大家帮帮忙呀· .net中gridview问题? 关于mp3下载问题,伤脑筋 关于girdview 导出 excel 高手进来帮帮忙啊
这是第一个表单,用Viewdata保存数据,页面要刷新就没了 public ActionResult addFile(FormCollection formvalues)
{
try
{
StringBuilder sb = new StringBuilder("");
foreach (string item in Request.Files)
{
HttpPostedFileBase file = Request.Files[item] as HttpPostedFileBase;
if (file == null && file.ContentLength == 0)
continue;
string path = Server.MapPath("~//UploadFile//");//上传的路径
if (!System.IO.Directory.Exists(path)) //如果不存在该路径,则创建
{
System.IO.Directory.CreateDirectory(path);
}
path = AppDomain.CurrentDomain.BaseDirectory + "UploadFile/"; string fileName = Path.GetFileName(file.FileName); string tempFileName = fileName.Substring(0, fileName.IndexOf('.')) + DateTime.Now.ToString("yyyyMMddHHmmss") + fileName.Substring(fileName.IndexOf('.'), fileName.Length - (fileName.IndexOf('.'))); file.SaveAs(Path.Combine(path, tempFileName)); //上传文件 Pub_Attachment att = new Pub_Attachment();
att.FileName = fileName;
att.FilePath = Path.Combine(path, tempFileName);
att.FileContext = "";
att.Status = "1";
att.Re = "";
//att.CreateBy=Session
att.CreateDate = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
attService.Insert(att);
//返回上传文件的ID
string tempID = (attService.Select(" and FilePath='" + att.FilePath + "' ")).SingleOrDefault().AttachmentID;
sb.Append(tempID + "|");
}
ViewData["File"] = sb;
return RedirectToAction("Doc_Model1_Add");
//return Content("<script>alert('上传文件成功');window.history.back();</script>");
}
catch (Exception ex)
{
log.Error(ex.Message, ex);
return Redirect(Request.ApplicationPath + "error.htm");
}
但是我不知道怎么弄了,我提交form1,上传到服务器,页面会刷新。