In .cshtml page, I have created the following method
@functions
{
public string GenerateSelect()
{
<select>
<option value="0">Ignore</option>
<option value="-1"></option>
</select>
return "";
}
}
Tried to use like
<td class="borderLeft">
@GenerateSelect()
</td>
but the code doesn't even compile and giving error
Error Severity Code Description Project File Line Suppression State Error MVC1006 The method contains a TagHelper and therefore must be async and return a Task. For instance, usage of ~/ typically results in a TagHelper and requires an async Task returning parent method.
If we use other simple html tag then the GenerateSelect() method works fine, like
public string GenerateSelect()
{
<div>
hello
</div>
return "";
}
What could be the problem?
Since your select option's contains value which will be regard as the html taghelper. So you should use System.Threading.Tasks.Task
instead of string as in your function method.
More details, you could refer to below codes:
@functions
{
async System.Threading.Tasks.Task GenerateSelect()
{
<select>
<option value="0">Ignore</option>
<option value="-1"></option>
</select>
}
}
@{await GenerateSelect();}
Result: