如何根据当前ID隐藏输入文本框? [英] How do I hide input textbox based on current ID?

查看:281
本文介绍了如何根据当前ID隐藏输入文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的程序,它根据用户选择的事件ID类型显示问题列表。我试图弄清楚如果事件id为1,我如何隐藏AnswerText的文本框,然后对于任何其他事件id,将显示文本框。





Hello below is my program that displays a list of questions based on the type of event id the user has selected. I am trying to figure out how can I hide the textbox that is for the AnswerText if the event id is 1 and then for any other event id the text box will be displayed.


@model IList<myProject.ViewModels.QuestionViewModel>

@{ 
    Layout = "~/Views/Shared/_Layout.cshtml";

}

@{ 
    ViewBag.Title = "Event Questions";
}

<h2> Event Questions</h2>
@using (Html.BeginForm("PostAnswers", "EventQuestions", FormMethod.Post))
{
    <table class="table">
        @for (var i = 0; i < Model.Count(); i++)
        {

            <tr>
                <td>
                   
                 
                    @Html.HiddenFor(x => x[i].EventId)
                    @Html.HiddenFor(x => x[i].QuestionId)
                    @Html.DisplayFor(x => x[i].QuestionText)
                    <br />
                  
                    @if ()
                    {
                        @Html.HiddenFor(x => x[i].AnswerText, new { @class = "form-control" }) 
                    }
                    else
                    {
                        @Html.TextBoxFor(x => x[i].AnswerText, new { @class = "form-control" })
                    
                    }
   
                     

                  

                </td>
            </tr>
        }
    </table>

    <input type="submit" value="Submit" class="btn btn-primary btn-md" />
    @*Html.ActionLink("Submit", "PostAnswers")*@
   
}





我尝试过的事情:



我正在考虑如果EventId = 1 {隐藏文本框}其他{显示的逻辑线文本框}。只是不知道正确的语法。



What I have tried:

I was thinking along the lines of logic of if EventId = 1 {hides textbox} else {displays textbox}. Just don't know the correct syntax.

推荐答案

@if (Model[i].EventId == 1)


@if (eventID == 1)
{
    Html.HiddenFor(x => x[i].AnswerText, new { @class = "form-control" });
}
else
{
    Html.TextBoxFor(x => x[i].AnswerText, new { @class = "form-control" });
}


这篇关于如何根据当前ID隐藏输入文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆