0
每次用户创建新评论时,都会尝试发送一封电子邮件。 我已经安装的软件包Postal.MVC5通过邮政mvc发送电子邮件
评论模型
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; }
NewCommentEmail型号
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 = "[email protected]";
email.UserName = nota.username;
email.Comment = nota.Asunto;
email.Send();
return RedirectToAction("Details", new { @id = localId });
}
catch
{
return View();
}
}
我也已将此添加到webconfig
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\Temp\" />
</smtp>
</mailSettings>
我得到的错误是: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:Couldn“T作出的时间连接在执行一个空引用
即得到错误的行是:
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
查看
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Notas Adjuntas</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div>
<ledgend>Datos del Local<ledgend>
<div class="panel-title">Id</div>
<div class="text-left">
<input type="Text" name="LocalID" id="LocalID" value="@ViewBag.Local.Id" />
</div>
<table class="table">
<tr>
<th>Id</th>
<th>Viejo Id</th>
<th>Nombre</th>
<th>Unificado Con</th>
<th>Dirección</th>
<th>Telefono</th>
<th>Localidad</th>
<th>Provincia</th>
<th>Proveedor</th>
<th>Estado</th>
<th>Fecha Instalación</th>
</tr>
<tr>
<td>@ViewBag.Local.NuevoId</td>
<td>@ViewBag.Local.ViejoId</td>
<td>@ViewBag.Local.NombreComercio</td>
<td>@ViewBag.Local.UnificadoCon</td>
<td>@ViewBag.Local.Direccion</td>
<td>@ViewBag.Local.Telefono</td>
<td>@ViewBag.Local.Localidad</td>
<td>@ViewBag.Local.Provincia</td>
<td>@ViewBag.Local.Proveedor.Nombre</td>
<td>@ViewBag.Local.Estado.State</td>
<td>@ViewBag.Local.FechaInstalacion</td>
</tr>
</table>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Asunto, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Asunto, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Asunto, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Detalle, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Detalle, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Detalle, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Fecha, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Fecha, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Fecha, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Hora, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Hora, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Hora, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
有没有更多的错误的细节?更多的信息?堆栈跟踪?内部异常? – mason
详细信息:Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:没有找到任何真正的编码NULL – EmiL
你能把它翻译成英文吗? Stack Overflow是一个英文网站,很难用另一种语言来帮助你。 – mason