gpt4 book ai didi

c# - 使用 ASP.NET MVC 时无法设置 CSS 显示属性

转载 作者:行者123 更新时间:2023-11-28 09:07:00 24 4
gpt4 key购买 nike

我有一个 View ,我需要为 Controller 中的 div 元素设置可见性,因此当执行一个逻辑时,它会设置 visibility: hidden display: none 并且当另一个逻辑被执行时它设置 visibility: visibledisplay:block

View 呈现时,我正在查看源代码并查看 div 的正确样式,但是,当 visibility:hidden 时,它仍然显示里面的内容div 标签。

这是我的 VIEW 的片段:

<div id="review" style="display:'<%:Model.Visibility%>'">
<p>
REVIEW:
<%:ViewData["Review"]%>
</p>
<input name="submit" id="submit" type="submit" value="OK"/>
</div>

这是来自 Controller 的片段:

public ActionResult Index(EsafeModel model,string submit, string create)
{
var button = submit ?? create;
model.Visibility = "none";
ViewData["done"] = null;

EsafeActions eSafe = new EsafeActions(model.Corporation, model.Region, model.PortfolioName);

if (button.Equals("Create"))//user clicks create. We need to validate the fields and display the review section
{
if (ModelState.IsValid)//pass validation for the entire form
{
if (ESafeData.ValidateData(eSafe))//if validated
{
ViewData["Review"] = ESafeData.CreateReview(eSafe);
model.Visibility = "block";
}
else
{
ModelState.AddModelError("message", "The region should be 2 characters long.");
}
}
else
{
ModelState.AddModelError("message", "Creation of Data failed. Please correct errors and try again.");
}
}
else if (button.Equals("OK"))//need to insert data
{
if (ESafeData.Create(eSafe))
{
ModelState.Clear();
if (ESafeData.Create(eSafe))
{
ViewData["Message"] = "E-Safe data created!!!";
model.Visibility = "none";
}
else
{
ViewData["Message"] = "Failed to Create E-Safe Data";
}
}
}
return View(model);
}

这是模型:

public class EsafeModel
{
string visibility = "hidden";

[Required(ErrorMessage="Required Field")]
[DisplayName("Corporation")]
public string Corporation { get; set; }

[Required(ErrorMessage = "Required Field")]
[DisplayName("Region")]
public string Region { get; set; }

[Required(ErrorMessage = "Required Field")]
[DisplayName("Portfolio Name")]
public string PortfolioName { get; set; }

public string Visibility
{
get { return this.visibility; }
set { this.visibility = value; }
}
}

我在这里错过了什么?

谢谢

最佳答案

解决了问题。

我的 div定义错误:<div id="review" style="display:'<%:Model.Visibility%>'">

不需要单引号

关于c# - 使用 ASP.NET MVC 时无法设置 CSS 显示属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26663867/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com