这是视图代码,此视图将显示一个列表 preInscription Demande 和两个按钮Valide
,Delete
第一个按钮允许Webmaster
To Inscription
,第二个按钮允许 Demande Refuse
。
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<J2V.Models.preinscrit>>" %>
// some Html Code
<% foreach (var item in Model) { %>
<li>
<div class="listinfo">
<h3>
<%: Html.DisplayFor(modelItem => item.Nag) %>
</h3>
<p>
<%: Html.DisplayFor(modelItem => item.Idag) %>
</p>
<span class="price"> <%: Html.DisplayFor(modelItem => item.Adrag) %> <%: Html.DisplayFor(modelItem => item.Vilag) %> <%: Html.DisplayFor(modelItem => item.Gov) %></span> <span class="media">Tel : <%: Html.DisplayFor(modelItem => item.Telag) %> |</span> <%: Html.DisplayFor(modelItem => item.Mailag) %>
</div>
<div class="listingbtns">
<span class="listbuttons"><%: Html.ActionLink("Valide", "Valide", new {mod= item}) %> |</span>
<span class="listbuttons"><%: Html.ActionLink("Supprime", "Delete", new { id=item.Idag }) %></span>
</div>
<div class="clear">
</div>
</li>
<% } %>
这是它允许Validate
预先登记并将数据添加到代理表和用户表的“有效”操作:
[HttpGet]
public ActionResult Valide(Models.preinscrit model )
{
var db = new Models.J2VEntities();
Models.agence ag = new Models.agence();
Models.user user = new Models.user();
ag.Adrag = model.Adrag ;
ag.Gov = model.Gov ;
ag.Idag = model.Idag;
ag.Mailag = model.Mailag;
ag.Nomag = model.Nag;
ag.Vilag = model.Vilag;
user.IsAdmin = false;
user.iduser = model.Idag;
user.password = Models.LogModel.register.CreateRandomPassword();
db.AddTouser(user);
db.AddToagence(ag);
return View("index");
}
当我点击Valide
我的视图页面时,我收到此错误:
System.NullReferenceException
在这条线上ag.Adrag = model.Adrag ;