Я уже установил пакет Postal.MVC5
Модель комментариев
public int Id { get; set; }
[Required]
[MinLength(3)]
[MaxLength(20)]
public string Asunto { get; set; }
[Required]
public string Detalle { get; set; }
[DataType(DataType.Date)]
public DateTime Fecha { get; set; }
[DataType(DataType.Time)]
public DateTime Hora { get; set; }
public virtual Local local { get; set; }
public virtual string username { get; set; }
Новая модель электронной почты для комментариев
public class NewCommentEmail : Email
{
public string To { get; set; }
public string UserName { get; set; }
public string Comment { get; set; }
}
Контроллер
[HttpPost]
public ActionResult AgregarComentario(NotasAdjuntas nota)
{
try
{
var localId = int.Parse(Request["LocalID"]);
nota.username = Session["Username"].ToString();
using (var db = new AutoContex())
{
nota.local = db.Locales.Find(localId);
db.Entry(nota.local).Reference(p => p.Proveedor).Load();
db.Notas.Add(nota);
db.SaveChanges();
}
var email = new NewCommentEmail();
email.To = "emilia.lasaga@pedidosya.com";
email.UserName = nota.username;
email.Comment = nota.Asunto;
email.Send();
return RedirectToAction("Details", new { @id = localId });
}
catch
{
return View();
}
}
Я также добавил это в веб-конфигурацию
Я получаю следующую ошибку:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:Не удалось установить соединение во время выполнения в NULL-ссылке
Строка, в которой возникает ошибка это:
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
Просмотр
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
Notas Adjuntas
@Html.ValidationSummary(true, "", new { @class = "text-danger" })Datos del Local
Id
Id
Viejo Id
Nombre
Unificado Con
Dirección
Telefono
Localidad
Provincia
Proveedor
Estado
Fecha Instalación
@ViewBag.Local.NuevoId
@ViewBag.Local.ViejoId
@ViewBag.Local.NombreComercio
@ViewBag.Local.UnificadoCon
@ViewBag.Local.Direccion
@ViewBag.Local.Telefono
@ViewBag.Local.Localidad
@ViewBag.Local.Provincia
@ViewBag.Local.Proveedor.Nombre
@ViewBag.Local.Estado.State
@ViewBag.Local.FechaInstalacion
@Html.LabelFor(model => model.Asunto, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Asunto, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Asunto, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Detalle, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Detalle, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Detalle, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Fecha, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Fecha, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Fecha, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.Hora, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Hora, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Hora, "", new { @class = "text-danger" })
Подробнее здесь: https://stackoverflow.com/questions/435 ... postal-mvc
Мобильная версия