我希望能够根据选定的单选按钮显示来 self 的模型的查询。
我的 View 代码是:
<asp:Label ID="lblQuestionType" runat="server" Text="Question Type"></asp:Label>
<ul>
<li><%=Html.RadioButton("QuestionType", "1", true) %> Multiple - Choice</li>
<li><%=Html.RadioButton("QuestionType", "2", false) %> Short Answer</li>
<li><%=Html.RadioButton("QuestionType", "3", false) %> Participant List</li>
</ul>
并且 1 、 2 或 3 的值被传递到包含以下内容的我的模型:
public string[][] GetQuestionTypes(int questionGroup)
{
string[][] resultArray; // message shown to user
OleDbDataReader MyOleDbDataReader = DBConn("SELECT COUNT(*) FROM QUESTION_TYPES WHERE Groupings = " + questionGroup);
MyOleDbDataReader.Read();
int size = Convert.ToInt32(MyOleDbDataReader.GetValue(0));
resultArray = new string[size][];
MyOleDbDataReader.Close();
MyOleDbConnection.Close();
for (int x = 0; x < size; x++)
{
resultArray[x] = new string[3];
}
MyOleDbDataReader = DBConn("SELECT QType_ID, Text, Description FROM QUESTION_TYPES WHERE Groupings = " + questionGroup);
if (MyOleDbDataReader.HasRows)
{
for (int i = 0; i < size; i++)
{
MyOleDbDataReader.Read();
resultArray[i][0] = Convert.ToString(MyOleDbDataReader["QType_ID"]);
resultArray[i][1] = Convert.ToString(MyOleDbDataReader["Text"]);
resultArray[i][2] = Convert.ToString(MyOleDbDataReader["Description"]);
}
}
MyOleDbDataReader.Close();
MyOleDbConnection.Close();
return resultArray;
}
我如何在 javascript 中显示从 GetQuestionTypes 方法作为 DropDownList 返回的数组?
非常感谢任何帮助!
最佳答案
您可以在同一页面上执行此操作吗?如果是,请查看在使用 jQuery 的 .getJSON 更改单选按钮时进行异步调用。您可以在 .getJSON 将调用的方法内为下拉列表构建 HTML。
关于c# - 单击 RadioButton 时,我想在 View 中显示模型中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6138734/