0
我有一個視圖,我需要從控制器設置div
元素的可見性,因此當執行一個邏輯時,它會設置visibility: hidden
或display: none
,並且當另一個邏輯是執行它設置visibility: visible
或display:block
。使用ASP.NET MVC時無法設置CSS顯示屬性
當呈現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>
這是從控制器片段:
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; }
}
}
缺少什麼我在這裏?
謝謝