Save the path of an image in the database using ASP.NET MVC 5

0

I want to select an image and save the image path in the database, because in the sql database the "Image" column is with type varchar . Could you help me with some examples? Thanks 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");
}
    
asked by anonymous 29.06.2017 / 17:02

0 answers