estoy haciendo un formulario en el tiene que tomar una foto y contestaran en un celular. he investigado lo mejor que encontré es usar HttpPostedFileBase pero me sale el parámetro null en Internet he visto ejemplos con solo la imagen pero también necesito enviar una clase .
Codigo Controlador
[HttpPost]
public ActionResult RecorrerAuditoria([Bind(Include = "Id,Answer,Comment,Assessment")] Audit_Question audit, HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
try
{
string path = Path.Combine(@"\\emxlocal01\LPA\Prueba Luis\Pictures\Audit", Path.GetFileName(file.FileName));
file.SaveAs(path);
ViewBag.Message = "File uploaded successfully";
if (audit.Answer.Equals("Success"))
{
audit.Status = "Closed";
audit.DateFinish = DateTime.Now;
audit.EmailSent = "noRequired";
}
else
{
audit.Status = "failure";
audit.EmailSent = "Pending";
}
audit.PictureR.SrcPic = path;
new Conn().RealizarQuestion(audit);
return View(SessionHelper.CurrentQuestion.FirstOrDefault());
}
catch (Exception ex)
{
ViewBag.Message = "ERROR:" + ex.Message.ToString();
}
else
ViewBag.Message = "You have not specified a file.";
return View();
}
Codigo vista
using (Html.BeginForm("RecorrerAuditoria", "Auditoria", FormMethod.Post, new
{ enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<div class="row form-group">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="col col-md-8"><h5 class="text-sm-center mt-2 mb-1">@Html.DisplayFor(a => a.rQuestion.Type)</h5></div>
</div>
<div class="row form-group">
<div class="col col-md-15">
@Html.DisplayFor(a => a.rQuestion.Question)
</div>
</div>
<div class="row form-group">
<div class="col col-md-9">
<div class="form-check-inline form-check">
@Html.RadioButtonFor(model => model.Answer, "Success", new { id = "Success", @class = "form-check-input" })
@Html.Label("Conforme", "Conforme")
@Html.RadioButtonFor(model => model.Answer, "Failure", new { id = "Failure", @class = "form-check-input" })
@Html.Label("No Conforme", "NoConforme")
</div>
</div>
</div>
<div class="row form-group">
<div class="col col-md-3"><label for="textarea-input" class="form-control-label">Observaciones</label></div>
<div class="col-12 col-md-9">@Html.TextAreaFor(model => model.Comment, new { @class = "form-control", placeholder = "Contenido...", @rows = "4", @name = "textarea-input", @id = "textarea-input" })</div>
</div>
<div class="row form-group">
<div class="col col-md-3"><label>foto verificacion:</label></div>
<input type="file" accept="image/*" capture="camera">
</div>
<div id="Groupfind" class="row form-group">
<div class="col col-md-3"><label>foto de falla:</label></div>
<input type="file" accept="image/*" capture="camera">
</div>
<div class="row form-group">
<div class="col col-md-3"><label class="form-control-label">Calif Auditor</label></div>
<div class="col col-md-9">
<div class="form-check-inline form-check">
@Html.RadioButtonFor(model => model.Assessment, "Excelente", new { id = "Excelente", @class = "form-check-input" })
@Html.Label("Excelente", "Excelente")
@Html.RadioButtonFor(model => model.Assessment, "Regular", new { id = "Regular", @class = "form-check-input" })
@Html.Label("Regular", "Regular")
@Html.RadioButtonFor(model => model.Assessment, "Deficiente", new { id = "Deficiente", @class = "form-check-input" })
@Html.Label("Deficiente", "Deficiente")
</div>
</div>
</div>
<hr>
<div class="card-text text-sm-center">
<button type="submit" class="btn btn-success btn-flat m-b-30 m-t-30">Siguiente</button>
</div>
</div>
} }