0
I want to select an image and save in the database the image path, because in the sql database the "Image" column is with the type varchar. Could you help me with some examples? I thank you in advance.
View to Insert:
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Adicionar Sistema</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Descricao, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Descricao, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Descricao, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DataInativo, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DataInativo, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DataInativo, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.BoletoConfigId, "BoletoConfigId", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.BoletoConfigId, TempData["BoletoConfigId"] as IEnumerable<SelectListItem>, "Selecione", htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.BoletoConfigId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UrlAcesso, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UrlAcesso, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.UrlAcesso, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Imagem, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<input type="file" id="imagem" name="imagem"/>
@*@Html.EditorFor(model => model.Imagem, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Imagem, "", new { @class = "text-danger" })*@
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Adicionar" class="btn btn-primary" />
</div>
</div>
</div>
Controller:
public ActionResult Inserir()
{
ViewBag.BoletoConfigId = new
SelectList(RepositorioBase<BancoBoletoConfiguracao>.GetAll(),
"BoletoConfigId", "Descricao");
return View();
}
[HttpPost]
public ActionResult Inserir(Sistema sistema)
{
RepositorioBase<Sistema>.Add(sistema);
return RedirectToAction("Listar");
}
Where’s your code, your View? your code that writes to the table... ?
– novic
Now they’re there! @Virgilionovic
– Thales Gilberto
Related: https://stackoverflow.com/questions/8551528/httppostedfilebase-always-return-null-in-asp-net-mvc
– novic
Related: https://answall.com/questions/216605/salvar-o-camio-de-uma-imagem-no-banco-dados-usando-asp-net-mvc-5?noredirect=1#comment442857_216605
– novic