PDA

View Full Version : سوال: نمایش داده در textbox در mvc



Iran58
پنج شنبه 24 فروردین 1396, 07:54 صبح
سلام
یک کنترل داریم
مانند کنترلر زیر


[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(UserLogin userLogin)
{
if(user==userLogin.user && pass==userLogin.pass)
{
return RedirectToAction("ChangePassword");
}
}

که کاربر را انتقال می دهد به صفحه ChangePassword انتقال می دهد
و کنترلهای تغییر پسورد هم بصورت زیر است
[HttpGet]
public ActionResult ChangePassword()
{
if (HttpContext.GetCookieValue("Existence") != "")
{
return View();
}
else
{
return RedirectToAction("Login");
}
}


[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ChangePassword(UserChangePassword userChangePassword)
{
var user = new UserRepositories();
if (ModelState.IsValid)
{
if (user.Update(UserMapper.UserChangePassword(userCha ngePassword)))
{
return RedirectToAction("Index");
}
else
{
return View("ChangePassword");
}
}
else
{
return View("Create");
}
}
و صفحه تغییر پسورد هم بصورت زیراست


@model Models.EntityView.UserChangePassword
@{
ViewBag.Title = "ChangePassword";
}


<h2>ChangePassword</h2>


@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.ValidationSummary(true)


<div class="form-group">
<div class="col-md-10">
@Html.EditorFor(model => model.UserName, new { htmlAttributes = new { @class = "form-control" , @Value = ViewBag._userName } })
@Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
</div>
@Html.LabelFor(model => model.UserName, htmlAttributes: new { @class = "control-label col-md-2" })
</div>
<div class="form-group">
<div class="col-md-10">
@Html.EditorFor(model => model.OldPassword, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
</div>
@Html.LabelFor(model => model.UserName, htmlAttributes: new { @class = "control-label col-md-2" })
</div>


<div class="form-group">
<div class="col-md-10">
@Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
</div>
@Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label col-md-2" })
</div>
<div class="form-group">
<div class="col-md-10">
@Html.EditorFor(model => model.ConfirmPassword, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ConfirmPassword, "", new { @class = "text-danger" })
</div>
@Html.LabelFor(model => model.ConfirmPassword, htmlAttributes: new { @class = "control-label col-md-2" })
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}


<div>
@Html.ActionLink("Back to List", "Index")
</div>


حال سوال من این است که چگونه وقتی می خواهم بروم صفحه تغییر پسورد تکس باکس UserName نام کاربری را دریافت کند و بصورت read only باشد
باتشکر

parsdarab
پنج شنبه 24 فروردین 1396, 08:46 صبح
سلام
از html.displayfor استفاده کن