Exception in template (Designs\Dwsimple\CustomerRelationManager/Users.cshtml): System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.cffcfbfbebbb.Execute()
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context)
   at RazorEngine.Templating.TemplateService.Run(ITemplate template, DynamicViewBag viewBag)
   at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName)
   at RazorEngine.Razor.Parse[T](String razorTemplate, T model, String cacheName)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()
@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> @using Dynamicweb.Security.UserManagement; @using Fjerdingstad.CustomModules.CustomModules.CustomerRelationManager; @{ var feedPageId = Pageview.Area.Item["Customer_Relation_API"].ToString(); var feedPage = "/Default.aspx?ID=" + feedPageId + "&Action=Users"; var userNameInput = CustomerRelationManager.UserName; var customerCompanyInput = CustomerRelationManager.CustomerCompany; var customerNameInput = CustomerRelationManager.CustomerName; var customerPhoneInput = CustomerRelationManager.CustomerPhone; var customerEmailInput = CustomerRelationManager.CustomerEmail; var customers = GetValue("CRM:Users.Customers") as List<User>; } <div class="row">&nbsp;</div> <div class="row"> <h3 class="dw-section-title text-center">@GetGlobalValue("Global:Page.Name")</h3> </div> <div class="row"> <div class="dealers-search col-md-7 col-sm-6 col-xs-12"> <input type="text" id="dealers-search-field" placeholder="@Translate("Type to search...")" /> <button class="btn btn-primary" type="submit"> <i class="fa fa-search"></i> </button> </div> <button type="button" id="createNew" class="btn btn-primary pull-right create-new"> @Translate("Create new profile") </button> </div> <div class="row">&nbsp;</div> <!-- Modal Edit User --> <div class="modal fade dealers-customers-user-edit" id="modalUser" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header clearfix"> <h3 id="modalHeader"></h3> <button type="button" class="close" data-dismiss="modal">&times;</button> </div> <div class="modal-body"> <form method="post" id="profile-form"> <input type="hidden" name="crm_action" id="crm_action" value="" /> <input type="hidden" name="crm_userID" id="crm_userID" value="" /> <div class="row"> <div class="w-box"> <div class="col-md-12 col-sm-12 col-xs-12"> <div class="row">&nbsp;</div> <div class="row" id="SaveUserErrorContainer" style="display: none;"> <div class="col-md-12 col-sm-12 col-xs-12"> <span id="SaveUserError" style="color: red;"></span> </div> </div> <div class="row">&nbsp;</div> <div class="row"> <div class="col-md-3 col-sm-3 col-xs-12"> <span>@Translate("Company name"):</span> </div> <div class="col-md-9 col-sm-9 col-xs-12"> <input class="form-control" name="@customerCompanyInput" id="@customerCompanyInput" type="text" value=""> </div> </div> <div class="row">&nbsp;</div> <div class="row"> <div class="col-md-3 col-sm-3 col-xs-12"> <span>@Translate("Name"):</span> </div> <div class="col-md-9 col-sm-9 col-xs-12"> <input class="form-control" name="@customerNameInput" id="@customerNameInput" type="text" value=""> </div> </div> <div class="row">&nbsp;</div> <div class="row"> <div class="col-md-3 col-sm-3 col-xs-12"> <span>@Translate("Customer email"):</span> </div> <div class="col-md-9 col-sm-9 col-xs-12"> <input class="form-control" name="@customerEmailInput" id="@customerEmailInput" type="email" value=""> </div> </div> <div class="row">&nbsp;</div> <div class="row"> <div class="col-md-3 col-sm-3 col-xs-12"> <span>@Translate("Customer Phone"):</span> </div> <div class="col-md-9 col-sm-9 col-xs-12"> <input class="form-control" name="@customerPhoneInput" id="@customerPhoneInput" type="text" value=""> </div> </div> <div class="row">&nbsp;</div> <div class="row"> <div class="col-xs-12"> <input class="btn btn-dw-primary pull-right submitter" type="button" onclick="saveUser();" id="submitter" value="@Translate("Save")"> </div> </div> </div> </div> </div> </form> </div> </div> </div> </div> <!-- Modal Delete User--> <div class="modal fade" id="modalDeleteUser" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header btn-primary"> <button type="button" class="close" data-dismiss="modal">&times;</button> </div> <div class="modal-body"> <div class="row">&nbsp;</div> <h5 class="text-center">@Translate("Are you sure you want to delete this user") ?</h5> <div class="row">&nbsp;</div> <div class="row"> <div class="col-md-6 col-xs-12"></div> <div class="col-md-3 col-xs-12"> <button type="button" id="modalDeleteUserBtn" class="btn btn-dw-primary btn-block" data-dismiss="modal" onclick="deleteUser()">@Translate("OK")</button> </div> <div class="col-md-3 col-xs-12"> <button type="button" class="btn btn-default btn-block" data-dismiss="modal">@Translate("Cancel")</button> </div> </div> </div> </div> </div> </div> <!-- Table --> <div class="dealers-customers-list table-responsive"> <table class="table table-hover"> <thead> <tr> <th>@Translate("Company name")</th> <th>@Translate("Name")</th> <th>@Translate("Email")</th> <th>@Translate("Phone number")</th> <th>@Translate("Created on")</th> <th>&nbsp;</th> </tr> </thead> <tbody> @foreach (var user in customers) { var customerCompany = user.Company; var userName = user.Name; var email = user.Email; var phone = !string.IsNullOrWhiteSpace(user.Phone) ? user.Phone : @Translate("-"); var userId = user.ID; var createdOn = user.CreatedOn.HasValue ? user.CreatedOn.Value.ToString("dd/MM/yyyy") : "-"; <tr> <td data-title="@Translate("Company name")">@customerCompany</td> <td data-title="@Translate("Name")">@userName</td> <td data-title="@Translate("Email")">@email</td> <td data-title="@Translate("Phone number")">@phone</td> <td data-title="@Translate("Created on")">@createdOn</td> <td align="center"> <button class="edit-profile" type="button" onclick="EditUser(@userId);"> <i class="fa fa-external-link fa-lg" aria-hidden="true" title="@Translate("Edit?")"></i> </button> <button class="deleateUserDealer" onclick="showDeleteUserModal(@userId);"> <i class="fa fa-trash-o fa-lg" aria-hidden="true" title="@Translate("Delete?")"></i> </button> </td> </tr> } </tbody> </table> </div> <div class="row">&nbsp;</div> <!-- Scripts --> <script> function Clear() { $('#@customerCompanyInput').val(''); $('#@customerPhoneInput').val(''); $('#@customerEmailInput').val(''); $('#@customerNameInput').val(''); $('#crm_action').val(''); $('#crm_userID').val(''); } function saveUser() { $.ajax("@feedPage", { method: "POST", data: $("#profile-form").serialize(), complete: function (data) { var json = data.responseJSON; if (json.error) { $("#SaveUserError").html(json.errorText); $("#SaveUserErrorContainer").show() } else { location.reload(); } } }); } function EditUser(id) { Clear(); $.getJSON("@feedPage&crm_action=Show&crm_userId=" + id, function(data) { $('#@customerCompanyInput').val(data.customerCompany); $('#@customerPhoneInput').val(data.phone); $('#@customerEmailInput').val(data.email); $('#@customerNameInput').val(data.userName); $('#crm_action').val('Update'); $('#crm_userID').val(data.userId); var header = '@Translate("Edit customer profile")'; $('#modalHeader').text(header); $('#modalUser').modal('show'); }); } function showDeleteUserModal(id) { $('#modalDeleteUserBtn').data('userID', id); $('#modalDeleteUser').modal('show'); } function deleteUser() { var id = $('#modalDeleteUserBtn').data('userID'); $.ajax("@feedPage&crm_action=Delete&crm_userId=" + id, { method: "GET", complete: function () { location.reload(); } }); } //Search $(document).ready(function () { $("#dealers-search-field").keyup(function () { var searchText = $(this).val().toLowerCase(); $.each($(".dealers-customers-list table tbody tr"), function () { if ($(this).text().toLowerCase().indexOf(searchText) === -1) $(this).hide(); else $(this).show(); }); }); $('#createNew').click(function () { Clear(); $("#crm_action").val("Create"); var header = '@Translate("Create new profile")'; $('#modalHeader').text(header); $('#modalUser').modal('show'); }) }); </script>