在visual studio中的同一文本框中显示输出

时间:2017-12-30 19:06:58

标签: html css asp.net-mvc razor

当我提供详细信息时,它将在新文本框中打印我指定的任何值,但我想打印我在文本框中给出的相同值。我正在使用[httppost]和[httpGet]命令。

在查看页面中,我有以下代码:

@{
    ViewBag.Title = "LoginPage";
}
<h1>LoginPage</h1>
 <form  method="post" action="/Home/LoginPage" >
     <table>
         <tr>
             <td>First Name : </td>
             <td><input type="text" id="txt.Fname" name="F_FIRSTNAME" class="form-control"/> </td> 
          </tr>
         <tr>
             <td> Last Name : </td>
             <td><input type="text" id="txt_LNAME" name="L_LastName" class="form-control"/></td> 
         </tr>
         <tr>
             <td>Password: </td> 
             <td><input type="password" id="txt_Password" name="P_PASSWORD" class="form-control" /> </td>
         </tr>
         <tr>
             <td>Email ID : </td>
             <td><input type="email" id="txt_emailid" name="E_EmailID" class="form-control" /> </td>
         </tr>
         <tr>
             <td><input type="submit" id="txt_Enter" name="Enter" class="btn-primary" /></td>
         </tr>
     </table>
 </form>

@{ 
    if(IsPost==true)
    {
        string name1 = Request["F_FIRSTNAME"]; 
        if(!string.IsNullOrEmpty(name1))
        {
            <h2 style=" color:aquamarine;" > <input type="text" value="@name1" /> </h2>
        }
        string name2 = Request["L_LASTNAME"];
        if (!string.IsNullOrEmpty(name2))
        {
            <h2 style="color:blue;"> <input type="text" value="@name2" /> </h2>
        }
        string name3 = Request["P_PASSWORD"];
        if (!string.IsNullOrEmpty(name3))
        {
            <h2 style="color:blue;"> <input type="text" value="@name3" /> </h2>
        }
        string name4 = Request["E_EMAILID"];
        if (!string.IsNullOrEmpty(name4))
        {
            <h2 style="color:blue;"> <input type="text" value="@name4" /></h2>
        }
        else
        {
            <h5>This is a get request </h5>
        }
    }

}

并在控制器中:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebApplication3.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult LoginPage()
        {
            return View(); 
        }
        [HttpPost]
        public ActionResult AfterLoginPage(string F_FIRSTNAME, stringL_LASTNAME, string P_PASSWORD, string E_EMAILID)
        {
             return View("LoginPage");
        }
    }
}

[正如您所见,凭据显示在我创建的单独文本框中但我想在同一文本框中显示] [在此处输入图像说明] 1

1 个答案:

答案 0 :(得分:0)

您只需更改表单并替换以下代码:

<form method="post" action="/Home/LoginPage">
        <table>
            <tr>
                <td>First Name : </td>
                <td><input type="text" id="txt.Fname" name="F_FIRSTNAME" class="form-control" value="@(IsPost ? Request["F_FIRSTNAME"]:"")" /> </td>
            </tr>
            <tr>
                <td> Last Name : </td>
                <td><input type="text" id="txt_LNAME" name="L_LastName" class="form-control" value="@(IsPost ? Request["L_LastName"]:"")" /></td>
            </tr>
            <tr>
                <td>Password: </td>
                <td><input type="password" id="txt_Password" name="P_PASSWORD" class="form-control" value="@(IsPost ? Request["P_PASSWORD"]:"")"/> </td>
            </tr>
            <tr>
                <td>Email ID : </td>
                <td><input type="email" id="txt_emailid" name="E_EmailID" class="form-control" value="@(IsPost ? Request["E_EmailID"]:"")"/> </td>
            </tr>
            <tr>
                <td><input type="submit" id="txt_Enter" name="Enter" class="btn-primary" /></td>
            </tr>
        </table>
</form>

您可以删除剩余的View代码。我还没有对它进行测试,但我认为它有效,尽管它不是正确的解决方案。最好有一个单独的ModelViewModel