如何设置在编辑视图中显示此内容和其他内容? [英] how can i set to show this and another in edit view ?

查看:123
本文介绍了如何设置在编辑视图中显示此内容和其他内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上我想做的是什么?
我想显示if(model.IsItem == true)
我想显示某些div,因为它是编辑视图中的项目
如果为假,那么我想隐藏此
我该怎么办?
请帮助!!
控制器:

actually what i want to do is?
i want to show the if (model.IsItem==true)
i want to show certain div as it is item in edit view
and if false then i want to hide this
how can i do that ?
plz help !!
controller :

public ActionResult Edit(int id )
 {
 var ParamToEdit = (from pd in _db.Dog join p in _db.animal on pd.dogid equals p.animalid
                    where pd.dogid == id
                    select new ArticleRepository { dog = pd, animal = p }).First();  
                     ViewBag.DTypes = (dat.GetStateName());
                     ViewBag.dp = (dat.GetTrueFalse()); 
                  return View(ParamToEdit);
            }


查看-


view--

@model MvcDemo.Models.ObjectManager.ArticleRepository
 
@{
      ViewBag.Title = "Edit";
}
   @using (Html.BeginForm())
         {
            @Html.ValidationSummary(true)  
            <ul><h2>Parameter</h2></ul>
            <div class="editor-label">
                  @Html.LabelFor(model => model.cat.catid)
            </div>
            <div class="editor-field">        
                  @Html.DisplayFor(model => model.cat.catid)
                  @Html.ValidationMessageFor(model => model.cat.catid)
            </div>
 
            <div class="editor-label">
                  @Html.editorfor(model => model.dog.dogid)
            </div>
if(model.animal.animaltype==dog)
{
   <div>@html.editorfor(model=model.dog.dogname)</div>
}
else hide this;

推荐答案

您可以将true/false保存在ViewData
中 例如:
you can save the true/false in ViewData
ex:
if (model.IsItem==true)
ViewData["IsItem"]="show"



在document.ready中,检查此数据并将一个CSS类应用于div.
例如:



In the document.ready check this data and apply a css class to div.
ex:

if ('<% =ViewData["IsItem"] %>'=='show')


(' #divId').addclass (' 显示');
('#divId').addclass('show');



并定义show css类,例如:



and define the show css class,such as:

 .show
{
display:block;
}


这篇关于如何设置在编辑视图中显示此内容和其他内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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