asp.net-mvc - MVC @html.textbox用于预填充 Guid 默认值

标签 asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 guid html.textboxfor

我的 Controller :

 [HttpGet]
 public ActionResult AddEstablishment()
 {     
    return View("AddEstablishment",new EstablishmentModel());
 }

我的模型:

public class EstablishmentModel
{
    [Display(Name = "Establishment ID")]
    public Guid EstablishmentId { get; set; }
    .............

我的 AddEstablishment View :

 @Html.TextBoxFor(x => x.EstablishmentId, new { @id = "inputEstGuid", @class = "input input-xlarge", @placeholder = "5C3B1CBC-2574-4E2A-A9FA-A8CA0041AB86" })

结果:

enter image description here

我的文本框已预填充 Guid 默认值

00000000-0000-0000-0000-000000000000

如何避免它?

请注意,我将模型实例传递给 View 有明显的原因。

最佳答案

这不应该起作用吗?

 public Guid? EstablishmentId { get; set; }

只需确保在最初显示 View 时该值为 null。

关于asp.net-mvc - MVC @html.textbox用于预填充 Guid 默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15137936/

相关文章:

javascript - 如何在特定页面停止 jQuery 插件?

c# - 如何在单击按钮时将数据从 View 发送到 Controller

javascript - 如何对选定的复选框行值求和?

Asp.net MVC - 多语言网站

c# - 使用 Entity Framework 时处理 ASP.NET MVC 中的必填字段

c# - 更新 ASP .Net MVC 中的记录

c# - GetUnobtrusiveValidationAttributes 总是返回一个空集合

javascript - 带有大列表的 Ajax 进度条

c# - ASP.NET MVC如何从应用程序中删除ViewState?

c# - 我想同时在两个模型上应用 for-each 循环 Asp.Net MVC