控制器
[HttpPost, ActionName("Signup")]
public ActionResult Signup_post(UserEditModel model)
{
if (!ModelState.IsValid) return View();
_registrationServices.Saveuser(model);
model.IsSubmitted = true;
model.Message = "Successfully Registered";
return View(model);
}
查看
if (Model != null)
{
if (Model.IsSubmitted != null && Model.IsSubmitted.Value)
{
@Html.LabelFor(m => m.Message, "Idon'twantthistext", new { @class = "alert-success" })
}
}
我正在更改我的模型消息以在控制器中成功注册,但在视图上它仍然呈现“Idon'twantthistext”,如果我在文本的标签中发送空白或没有任何内容,则它将“消息”显示为文本。我只是希望标签显示我从模型发送的文本。 我希望我很清楚。
答案 0 :(得分:1)
//LabelFor is used to generate the label of Field like Message, User, Password etc
@Html.LabelFor(model => model.Message)
//Label is used to generate the label for Value of Field (Just for view) like "Hello!", "Admin", "M4rt!4n" etc
@Html.Label("Message", Model.Message)
//TextBoxFor is used to generate the Edit for Value of field (To be edited) like "Hello!", "Admin", "M4rt!4n" etc
@Html.TextBoxFor(model => model.Message)
答案 1 :(得分:0)
@ Html.LabelFor仅用于显示属性名称而不是文本。
我所做的一切
@ Html.Label(Model.Message,new {@class =" text-success"})
现在它正在工作。
感谢 @Stephen Muecke 分享这些知识