Answer the question
In order to leave comments, you need to log in
MVC how to output modified text to HTML code from input on page reload?
Good afternoon.
Just started learning MVC. Mastering according to official documents and site metanit.com
HTML
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<div class="form-group">
<input type="email" class="form-control input-lg" id="exampleInputEmail2" placeholder="Your Email*">
</div>
<button type="submit" class="btn btn-info button">Подпишитесь</button>
<p>@ViewData["Test"]</p>
}
public IActionResult Index(string exampleInputEmail2)
{
ViewData["Test"] = exampleInputEmail2 + "_ТестТекст";
return View();
}
<p>@ViewData["Test"]</p>
Answer the question
In order to leave comments, you need to log in
Model:
public class UserContainer
{
public string Fam { get; set; }
public string Name { get; set; }
public string Name2 { get; set; }
public UserContainer(string F, string N, string N2)
{
Fam = F; Name = N; Name2 = N2;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Vasya.Models;
namespace Vasya.Controllers
{
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
UserContainer UCon = new UserContainer("","","");
return View(UCon);
}
[HttpPost]
public ActionResult Index(string Fam, string Name, string Name2)
{
UserContainer UCon = new UserContainer(Fam, Name, Name2);
return View(UCon);
}
}
}
@model System.Data.DataTable
<div>
Привет, @Model.Fam   @Model.Name   @Model.Name2
<form action="/Home/Index" method="post">
<p><input class="text-box single-line" size = 20 id ="N1" name ="Fam" type ="text" value = "@Model.Fam" /> </p>
<p><input class="text-box single-line" size = 20 id ="N2" name ="Name" type ="text" value = "@Model.Name" /> </p>
<p><input class="text-box single-line" size = 20 id ="N3" name ="Name2" type ="text" value = "@Model.Name2" /> </p>
<input type="submit" id="SendButton" value="Ok" />
</form>
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question