模型
public partial class Assignment
{
public Assignment()
{
this.CourseAvailables = new HashSet<CourseAvailable>();
}
public string AssignmentID { get; set; }
public Nullable<System.DateTime> SubmissionDate { get; set; }
public string Status { get; set; }
public Nullable<decimal> Mark { get; set; }
public string Comments { get; set; }
public string FileLocation { get; set; }
public virtual ICollection<CourseAvailable> CourseAvailables { get; set; }
}}
Run Code Online (Sandbox Code Playgroud)
调节器
public ActionResult Create(Assignment assignment)
{
if (ModelState.IsValid)
{
db.Assignments.Add(assignment);
db.SaveChanges();
return RedirectToAction("Index");
}
return …
Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc httppostedfilebase asp.net-mvc-3 asp.net-mvc-4
Delete
单击后,这就是我的功能。谁能告诉我如何执行简单的确认功能?
ASP.net C#。
以前我有这个
ScriptManager.RegisterStartupScript(this,
this.GetType(),
"script",
"confirm('Are you sure you want to Delete Your Discussion?');",
true);
Run Code Online (Sandbox Code Playgroud)
但以上代码在删除后运行。
protected void lnk_delete_Click(object sender, EventArgs e)
{
GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer;
string fieldID = grdrow.Cells[0].Text;
string query = "Delete from Comment where DiscussionID=@id";
SqlCommand cmd = new SqlCommand(query, cn);
cmd.Parameters.AddWithValue("@id", fieldID);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
string query1 = "Delete from Discussion where DIscussionID=@id";
SqlCommand cmd1 = new SqlCommand(query1, cn);
cmd1.Parameters.AddWithValue("@id", fieldID);
cn.Open();
cmd1.ExecuteNonQuery();
cn.Close();
GridView1.DataBind();
}
Run Code Online (Sandbox Code Playgroud) 有人介意指导我,如何将文件保存到我的数据库中,并在可能的情况下检索它,我还是这个 C# 和 MVC 4 的新手。我的数据库分配包含一个属性调用 FileLocation,它是 varBinary (MAX)。
public partial class Assignment
{
public Assignment()
{
this.CourseAvailables = new HashSet<CourseAvailable>();
}
public string AssignmentID { get; set; }
public Nullable<System.DateTime> SubmissionDate { get; set; }
public string Status { get; set; }
[Range(0,100, ErrorMessage="Only Value between 0-100 is accepted.")]
public Nullable<decimal> Mark { get; set; }
public string Comments { get; set; }
public byte[] FileLocation { get; set; }
public virtual ICollection<CourseAvailable> CourseAvailables { get; set; } …
Run Code Online (Sandbox Code Playgroud) 我之前已将文件上传到我的数据库,现在我想从我的数据库下载该文件.
谁能告诉我怎么样?我是C#和ASP.NET MVC的新手.
控制器:
public ActionResult Details(string id = null)
{
Assignment assignment = db.Assignments.Find(id);
if (assignment == null)
{
return HttpNotFound();
}
return View(assignment);
}
Run Code Online (Sandbox Code Playgroud)
模型:
public string AssignmentID { get; set; }
public Nullable<System.DateTime> SubmissionDate { get; set; }
public string Status { get; set; }
[Range(0,100, ErrorMessage="Only Value between 0-100 is accepted.")]
public Nullable<decimal> Mark { get; set; }
public string Comments { get; set; }
public byte[] FileLocation { get; set; }
Run Code Online (Sandbox Code Playgroud)
视图:
<div class="display-label">
<%: …
Run Code Online (Sandbox Code Playgroud)