Error executing template "Designs/Forney/Forms/Form/StandardFormDealerAddAddress.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_6282ad6f14ce45b5bd40f840ef764b42.Execute() in f:\Domains\Sites\forneyind.com\Files\Templates\Designs\Forney\Forms\Form\StandardFormDealerAddAddress.cshtml:line 57
at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at Dynamicweb.Rendering.Template.RenderRazorTemplate()
1 @inherits RazorTemplateBase<RazorTemplateModel<Template>>
2 @using Dynamicweb.Rendering;
3 @using Dynamicweb.Security.UserManagement;
4 @{
5 Dynamicweb.Content.Items.Item areaItem = Pageview.Area.Item;
6 // todo change to a Ajax Handler
7 Dynamicweb.Ecommerce.International.CountryCollection countries = Dynamicweb.Ecommerce.International.Country.GetCountries();
8 Dynamicweb.Ecommerce.International.CountryCollection regions = Dynamicweb.Ecommerce.International.Country.GetRegions(countries.First().Code2);
9 bool userIsLoggedIn = Dynamicweb.Security.UserManagement.User.IsExtranetUserLoggedIn();
10
11 if(countries.Any()){
12 @: @SnippetStart("jsVariables") var countryRegions = {}; @SnippetEnd("jsVariables")
13
14 foreach(var country in countries.OrderBy(s => s.CountryText.Name)){
15 Dynamicweb.Ecommerce.International.CountryCollection tempRegions = Dynamicweb.Ecommerce.International.Country.GetRegions(country.Code2);
16
17 if(tempRegions.Any()){
18 @: @SnippetStart("jsVariables") countryRegions.@(country.Code2) = {}; @SnippetEnd("jsVariables")
19 <text>
20 @SnippetStart("jsVariables")
21 countryRegions.@(country.Code2).code = [];
22 countryRegions.@(country.Code2).name = [];
23 @SnippetEnd("jsVariables")
24 </text>
25 foreach(var region in tempRegions.OrderBy(s => s.CountryText.Name)){
26 <text>
27 @SnippetStart("jsVariables")
28 countryRegions["@country.Code2"].code.push("@region.RegionCode");
29 countryRegions["@country.Code2"].name.push("@region.CountryText.Name");
30 @SnippetEnd("jsVariables")
31 </text>
32 }
33 }
34 }
35 }
36
37 User currentUser = User.GetCurrentUser();
38
39
40
41 bool formLabelBold = GetBoolean("Form.LabelBold"),
42 formLabelOverField = GetBoolean("Form.LabelOverField");
43 int formColumnShiftFormfieldId = GetInteger("Form.ColumnShiftFormfieldId");
44 string formCssClass = GetString("Form.CssClass"),
45 formSystemFields = GetString("Form.SystemFields"),
46 formId = GetString("Form.HtmlId"),
47 formOnSubmit = GetString("Form.OnSubmit"),
48 formSpamScript = GetString("Form.SpamScript"),
49 formAction = GetString("Form.Action"),
50 formLabelRequired = GetString("Form.LabelRequired"),
51 horizontalLabel = formLabelOverField ? "col-sm-3" : "";
52 string errorMessages = "";
53
54 if (formLabelOverField)
55 {
56 formCssClass += " form-horizontal";
57 }
58 }
59 <form novalidate method="post" action="@formAction" enctype="multipart/form-data" class="@formCssClass DMForms" id="@formId" onsubmit="@formOnSubmit">
60 <input type="hidden" id="Company" name="Company" value='@currentUser.Company'/>
61 <input type="hidden" id="CustomerNumber" name="CustomerNumber" value='@currentUser.CustomerNumber'/>
62
63 @formSystemFields
64 <div class="form-fields">
65 @if (formColumnShiftFormfieldId > 0)
66 {
67 @GetStartTable();
68 }
69
70 @foreach (LoopItem field in GetLoop("Fields"))
71 {
72 int fieldId = field.GetInteger("Field.ID");
73 bool fieldIsButton = field.GetBoolean("Field.IsButton"),
74 fieldIsList = field.GetBoolean("Field.IsList"),
75 fieldRequired = field.GetBoolean("Field.Required");
76 string fieldHtmlId = field.GetString("Field.HtmlId"),
77 fieldName = field.GetString("Field.Name"),
78 fieldControl = field.GetString("Field.Control"),
79 fieldDescription = field.GetString("Field.Description"),
80 required = fieldRequired ? "required" : "",
81 mandatory = fieldRequired ? "mandatory" : "",
82 fieldPrepend = field.GetString("Field.Prepend"),
83 fieldAppend = field.GetString("Field.Append"),
84 fieldType = field.GetString("Field.Type"),
85 fieldClass = field.GetString("Field.CssClass");
86 bool fieldHasPrepend = !string.IsNullOrEmpty(fieldPrepend),
87 fieldHasAppend = !string.IsNullOrEmpty(fieldAppend);
88 @* no labels *@
89 @*string hide = "hide";*@
90 @* with labels *@
91 string hide = "";
92
93 if (fieldHasAppend && fieldAppend.StartsWith("fa-"))
94 {
95 fieldAppend = string.Format("<i class=\"fa {0}\"></i>", fieldAppend);
96 }
97 if (fieldHasPrepend && fieldPrepend.StartsWith("fa-"))
98 {
99 fieldPrepend = string.Format("<i class=\"fa {0}\"></i>", fieldPrepend);
100 }
101 bool isInputGroup = fieldHasAppend || fieldHasPrepend;
102
103 <fieldset class="@fieldType @fieldClass @mandatory">
104
105
106 @* no labels *@
107 @*
108 @if (!fieldIsButton && (fieldType != "TextInput" && fieldType != "Textarea" && fieldType != "Text"))
109 {
110 hide = "";
111 }
112 *@
113
114 @* With labels *@
115 @if (fieldType == "Submit" || fieldType == "CheckBox" || fieldType == "Text" )
116 {
117 hide = "hide";
118 }
119
120 <label for="@fieldHtmlId" class="@hide control-label form-label">@fieldName</label>
121
122 @if(fieldIsList)
123 {@GetStartGroup()}
124 @if (fieldHasPrepend)
125 {<div class="input-group-addon">@fieldPrepend</div>}
126 @if (fieldType != "Submit")
127 {
128 if(field.GetLoop("Options").Any() && fieldType != "Select") {
129 foreach (LoopItem option in field.GetLoop("Options"))
130 {
131 if(fieldType == "Radio") {
132 <label class="radioBoxContainer" for='@option.GetString("Option.Value")_@field.GetString("Field.SystemName")'>
133 <input @required name='@field.GetString("Field.SystemName")' id='@option.GetString("Option.Value")_@field.GetString("Field.SystemName")' title='@option.GetString("Option.Value")' value='@option.GetString("Option.Value")' type="radio" />
134 <span>@option.GetString("Option.Text")</span>
135 </label>
136 }
137 else if(fieldType == "CheckBoxList") {
138 <label class="checkBoxContainer" for='@option.GetString("Option.Value")_@field.GetString("Field.SystemName")'>
139 <input @required name='@field.GetString("Field.SystemName")' id='@option.GetString("Option.Value")_@field.GetString("Field.SystemName")' title='@option.GetString("Option.Value")' value='@option.GetString("Option.Value")' type="checkbox" />
140 <span>@option.GetString("Option.Text")</span>
141 </label>
142 }
143
144 }
145 }
146 else {
147 if(fieldType == "CheckBox") {
148 <label class="checkBoxContainer" for='@GetString("Form.Field.checkboxfield.SystemName")'>
149 <input @required name='@GetString("Form.Field.checkboxfield.SystemName")' id='@GetString("Form.Field.checkboxfield.SystemName")' value='@GetString("Form.Field.checkboxfield.Value")' type="checkbox" />
150 <span>@GetString("Form.Field.checkboxfield.Name")</span>
151 </label>
152 }
153 else if (fieldType == "Select" && fieldClass.Contains("country") ) {
154 bool firstTime = true;
155
156 <select data-live-search="true" class="@fieldClass" name="@(field.GetString("Field.SystemName"))">
157 <option value="">@Translate("country", "Country")</option>
158 @RenderSnippet("highlightedContries")
159 @foreach (var option in countries.OrderBy(s => s.CountryText.Name))
160 {
161 string code = option.Code2.ToString();
162
163 if(firstTime && (code == "CA" || code == "US")) {
164 @SnippetStart("highlightedContries")
165 <option value="@code">@option.CountryText.Name</option>
166 @SnippetEnd("highlightedContries")
167 }
168 <option value="@code">@option.CountryText.Name</option>
169 }
170 @if(firstTime) {
171 @SnippetStart("highlightedContries")
172 <option disabled="disabled" value="">
173 ----------------
174 </option>
175 @SnippetEnd("highlightedContries")
176 }
177 </select>
178
179 }
180 else {
181 @fieldControl.Replace("<select", "<select "+ "data-live-search=\"true\"")
182 }
183 }
184
185 }
186 else
187 { <div class="formButtons">@fieldControl.Replace("<input ", "<input class='btn btn-bg'")</div> }
188
189 @if (fieldHasAppend)
190 {<div class="input-group-addon">@fieldAppend</div>}
191 @if(fieldIsList)
192 {@GetEndGroup()}
193 @if (!string.IsNullOrEmpty(fieldDescription))
194 {<p class="help-block"><small>@fieldDescription</small></p>}
195 </fieldset>
196
197
198
199
200 if (formColumnShiftFormfieldId == fieldId)
201 {
202 @GetShiftColumn();
203 }
204 }
205
206 @if (formColumnShiftFormfieldId > 0)
207 {
208 @GetEndTable();
209 }
210
211 </div>
212
213 </form>
214
215 @SnippetStart("jsOnLoadVariables")
216 obj_dataManagementForms.str_findText = '@Translate("FindFileText", "Find")';
217 @SnippetEnd("jsOnLoadVariables")
218
219 @SnippetStart("jsOnLoad")
220 onLoadValidatePageForms($('#@formId'), true);
221
222 $(".bootstrap-select.country").each(function(){
223 $(this).find("ul").children("li").eq(0).hide();
224 $(this).find("ul").children("li").eq(3).find("a").click()
225
226 });
227 $('fieldset #Company').parents("fieldset").remove();
228 $('fieldset #CustomerNumber').parents("fieldset").remove();
229 @SnippetEnd("jsOnLoad")
230
231
232
233
234
235
236 @functions {
237 private string GetStartTable()
238 {
239 return "<div class=\"row\"><div class=\"col-xs-6\">";
240 }
241
242 private string GetShiftColumn()
243 {
244 return "</div><div class=\"col-xs-6\">";
245 }
246
247 private string GetEndTable()
248 {
249 return "</div></div>";
250 }
251 private string GetStartGroup()
252 {
253 return "<div class=\"input-group\">";
254 }
255 private string GetEndGroup()
256 {
257 return "</div>";
258 }
259 }
260
261
262