I am passing a list of strings into a razor view page and I'd like to check if there are any errors before rendering the HTML asking to correct them.
My code compiles fine but generates a compile error when the page is rendered. The error is:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1501: No overload for method 'Write' takes 0 arguments
And here is the code that I'm trying to render:
@model UNICH.Settings.SettingsModel
@{
ViewBag.Title = "Edit";
}
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
@{
// Retrieve the server generated config errors from the ViewData
List<string> errors = ViewData["ConfigErrors"] as List<string>;
if( errors != null && errors.Count > 0 )
{
// We have some errors to display
<div>
<h3>The following errors need attention before the configuration can be saved</h3>
<ul>
@foreach( var error in errors)
{
// Display the errors that require attention
<li>
@error
</li>
}
</ul>
</div>
}
}
<fieldset>
<legend>Database Configuration</legend>
<table>
<tr>
<th>
Parameter
</th>
<th>
Value
</th>
<th>
Error
</th>
</tr>
<tr>
<td>
<h4>
Database Type</h4>
</td>
<td>
@Html.DropDownListFor(model => model.DBType, ViewData["DBTypes"] as SelectList, "select a value")
</td>
<td>
@Html.ValidationMessageFor(model => model.DBType)
</td>
</tr>
<tr>
<td>
<h4>
Server Name</h4>
</td>
<td>
@if( Model.DBType != "Oracle")
{
@Html.EditorFor(model => model.DBServerName)
}
</td>
<td>
@Html.ValidationMessageFor(model => model.DBServerName)
</td>
</tr>
<tr>
<td>
<h4>
Instance Name</h4>
</td>
<td>
@Html.EditorFor(model => model.DBInstanceName)
</td>
<td>
@Html.ValidationMessageFor(model => model.DBInstanceName)
</td>
</tr>
<tr>
<td>
<h4>
DB User Name</h4>
</td>
<td>
@Html.EditorFor(model => model.DBUsername)
</td>
<td>
@Html.ValidationMessageFor(model => model.DBUsername)
</td>
</tr>
<tr>
<td>
<h4>
Database Password</h4>
</td>
<td>
@Html.EditorFor(model => model.DBPassword)
</td>
<td>
@Html.ValidationMessageFor(model => model.DBPassword)
</td>
</tr>
</table>
</fieldset>
<div>
<p>
<input type="submit" value="Save" />
</p>
</div>
}
<div>
@Html.ActionLink("Discard Changes", "Index")
</div>
@{ }surrounding it. You should post your solution as the answer and accept it.