Asp.net mvc 3 @Html.EditorFor的硬代码值

Asp.net mvc 3 @Html.EditorFor的硬代码值,asp.net-mvc-3,Asp.net Mvc 3,我的MVC 3应用程序需要创建新用户 我想为视图中的ApplicationId文本框硬编码ApplicationId 有人知道怎么做吗 create方法不获取任何数据: public ActionResult Create() { return View(); } <div class="editor-label"> @Html.LabelFor(model => model.ApplicationId) </div

我的MVC 3应用程序需要创建新用户

我想为视图中的ApplicationId文本框硬编码ApplicationId

有人知道怎么做吗

create方法不获取任何数据:

public ActionResult Create()
{
    return View();
}


  <div class="editor-label">
            @Html.LabelFor(model => model.ApplicationId)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ApplicationId)
            @Html.ValidationMessageFor(model => model.ApplicationId)
        </div>

当然,在服务于此视图的控制器操作中,您只需在视图模型上设置相应的属性:

public ActionResult Foo()
{
    var model = ... go and fetch your model from somewhere
    model.ApplicationId = "some hardcoded value";
    return View(model);
}

现在,
EditorFor
将显示正确的值。无法强制视图中的值。编辑器模板的全部要点是它们使用为视图模型设置的值。

我无法在create methodErm中获取数据,请原谅?我不确定我是否理解你的评论及其与主题的关系。您不能获取数据吗?我想你首先要告诉我们更多关于这些数据的信息。然后关于取回等等。。。这样我们就可以知道,如果。我刚刚上传了我的创建方法。正如你所看到的,它没有获取任何数据换句话说,我没有返回任何东西。我仍然不理解你的话。你什么也不退?你在说什么?您的控制器操作将模型传递给此强类型视图,不是吗?否则,使用诸如Html.EditorFor之类的强类型帮助程序是毫无意义的。我想你必须展示你的控制器动作,因为我不知道你在说什么。
public ActionResult Foo()
{
    var model = ... go and fetch your model from somewhere
    model.ApplicationId = "some hardcoded value";
    return View(model);
}