【问题标题】:Page visible only if user is selected页面仅在用户被选中时可见
【发布时间】:2021-10-02 06:34:23
【问题描述】:

我只想在最初选择用户时才显示用户权限页面。这是在cshtml中选择用户的代码:

<div class="p-a-1">
    <select required class="form-control" style="overflow:auto;" id="Username">
        <option id="tipoUtente" value="0">&lt;Selezionare un utente&gt;</option>
        @foreach (var utente in
    GestioneUtenti.Select(new WhereStatementBuilder { { GestioneUtenti.Empty.Ruolo, Operator.Equals, 2} }))
        {
            <option value="@utente.IdUser">@utente.Username</option>
        }
    </select>
</div>

然后我添加权限:

<div class="p-a-1">
    <select required class="form-control" style="overflow:auto;" id="Username">
        <option id="tipoUtente" value="0">&lt;Selezionare un utente&gt;</option>
        @foreach (var utente in
    GestioneUtenti.Select(new WhereStatementBuilder { { GestioneUtenti.Empty.Ruolo, Operator.Equals, 2} }))
        {
            <option value="@utente.IdUser">@utente.Username</option>
        }
    </select>
</div>

在选择用户之前,我必须添加什么类型的控件才能隐藏页面?

【问题讨论】:

    标签: c# asp.net razor


    【解决方案1】:

    由于该项目是一个剃须刀项目,您可以通过某种方法为页面提供服务。例如,

    public ActionResult Index()
    {
        // some code
        return View();
    }
    

    如果权限页面不可见,您也愿意显示其他内容。在要显示的视图中添加 if 条件。像这样:

    public ActionResult Permissions()
    {
        if(userSelected())
            return View(); // shows permissions view
        return View("UserNotSelected"); // shows the view with some error message
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-23
      • 2020-02-11
      • 2011-10-31
      • 2019-10-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多