code in data Accesslayer
public class DataAccess
{
public void SaveFileName(string fileName)
{
string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("spnotaryfiles", con);
cmd.Parameters.AddWithValue("@Filename", fileName);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
cmd.ExecuteNonQuery();
}
}
}
Code in Action Controller
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
if(file != null && file.ContentLength > 0)
{
try
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Images/"), fileName);
file.SaveAs(path);
entity.filename = fileName;
da.SaveFileName(fileName);
}
catch (Exception ex)
{
throw ex;
}
}
return View();
}
Code in View
@using (Html.BeginForm("Index", "File", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" /><br />
<input type="submit" name="Submit" id="Submit" value="Upload" />
}
Getting Exception that saying
@using (Html.BeginForm("Index", "File", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" /><br />
<input type="submit" name="Submit" id="Submit" value="Upload" />
}
please help me to how to pass parameter to storedprocedure from controller