C# 能否在中间添加if-else语句<;tr>;.cshtml文件中的标记
我正在visual studio 2015中编写一个程序,在一个表中有一个下拉列表,用户可以在其中选择值,我想通过在标记的标记中使用if-else语句,根据用户选择更改下一行的内容。 这可能吗 我的cshtml代码:C# 能否在中间添加if-else语句<;tr>;.cshtml文件中的标记,c#,asp.net-mvc,razor,visual-studio-2015,C#,Asp.net Mvc,Razor,Visual Studio 2015,我正在visual studio 2015中编写一个程序,在一个表中有一个下拉列表,用户可以在其中选择值,我想通过在标记的标记中使用if-else语句,根据用户选择更改下一行的内容。 这可能吗 我的cshtml代码: <tr> <td> @Html.DropDownList( "Actions_performed", new SelectList(ViewBag.Actions_performed,
<tr>
<td>
@Html.DropDownList(
"Actions_performed",
new SelectList(ViewBag.Actions_performed, "Key", "Value"),
"--select--",
new { @class = "form-control" });
</td>
</tr>
<tr>
<td>
<!--make ajax here -->
@if (Model.ActionSelected == "keyvalueofselectedaction")
{
string x = "this text";
Console.WriteLine(x);
}
else
{
string upload = "upload file here!";
Console.WriteLine(upload);
}
</td>
</tr>
@Html.DropDownList(
“执行的操作”,
新建选择列表(ViewBag.Actions\u执行的“键”、“值”),
“--选择--”,
新的{@class=“form control”});
@if(Model.ActionSelected==“keyvalueofselectedaction”)
{
string x=“此文本”;
控制台写入线(x);
}
其他的
{
string upload=“在此处上载文件!”;
控制台写入线(上传);
}
不要使用Console.WriteLine它用于控制台应用程序,而不是web应用程序
Razor允许您在{和}中编写HTML。
您还可以使用Html.Raw(“此处为原始Html”)
更多信息请点击此处:简短回答,是的。但是“是/否”问题不适用于堆栈溢出。如果您需要解决方案编码方面的帮助,请使用更多WIP代码更新本文。是的,您可以:)使用jQuery/javascript根据下拉选择更新DOM。
Console.WriteLine()代码>?您试图通过控制台.WriteLine实现什么?