Hi alya14,
You are using MutRespond as model for the view. So there is no need to use Ajax.
Use Html.BeginForm to pass the data to controller.
Refer below sample.
Model
public class MutRespond
{
public string Durumu { get; set; }
public string Respond { get; set; }
public HttpPostedFileBase FileUpload { get; set; }
}
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View(new MutRespond());
}
[HttpPost]
public ActionResult CustomerRespond(MutRespond model)
{
string path = Server.MapPath("~/Uploads/");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
if (model.FileUpload != null)
{
string fileName = Path.GetFileName(model.FileUpload.FileName);
model.FileUpload.SaveAs(path + fileName);
}
return View();
}
}
View
@model _208920_File_With_Model_MVC.Models.MutRespond
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
@using (Html.BeginForm("CustomerRespond", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<span>Select File:</span>
@Html.TextBoxFor(m => m.FileUpload, new { type = "file", style = "margin-left: 3%;" })
<br />
<span>Durumu:</span>@Html.TextBoxFor(m => m.Durumu)
<br />
<span>Respond:</span>@Html.TextBoxFor(m => m.Respond)
<hr />
<input type="submit" value="Respond" />
}
</body>
</html>
Screenshot