@model WebApplication1.Controllers.DataModel;
<form asp-controller="Home" asp-action="Index" method="post">
<div class="row">
<div class="col-12 col-lg-10 offset-1">
<ej-rte ej-for="RTEvalue" name="RTEvalue" id="input" width="820px"></ej-rte>
</div>
</div>
<div class="row">
<div class="col-12 col-lg-10 offset-1">
<button type="submit" class="btn btn-sm btn-primary mt-1">Button_Save</button>
</div>
</div>
</form> |
DataModel model = new DataModel();
public IActionResult Index()
{
List<Tables> data = new List<Tables>();
string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\WebApplication1-2055850166\WebApplication1\WebApplication1\Data\NORTHWND.MDF;Integrated Security=True;Connect Timeout=30";
SqlCommand sqlCommand = new SqlCommand();
SqlConnection sqlc = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
using (sqlc)
{
sqlc.Open();
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("select * From [Table]",
sqlc);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
data.Add(new Tables((byte[])myReader["byte"]));
model.RTEvalue= (myReader["value"].ToString());
}
sqlc.Close();
}
return View(model);
}
[HttpPost]
public ActionResult Index(DataModel data)
{
string value = data.RTEvalue;
//do the action here.
return View();
} |
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<ej:RTE ID="RTESite" runat="server" Width="700px" AllowEditing="true">
</ej:RTE>
<asp:Button ID="submit" runat="server" Text="Submit" OnClick="submit_Click" />
</asp:Content> |
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack != true)
{
string rootpath = HttpContext.Current.Server.MapPath("~/App_Data/NORTHWND.MDF");
string constr = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + rootpath + ";Integrated Security=True;Connect Timeout=30";
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlDataAdapter adpt = new SqlDataAdapter("select * from RTE", con);
DataTable dt = new DataTable();
adpt.Fill(dt);
List<String> RteValue = new List<String>();
RteValue = dt.AsEnumerable()
.Select(r => r.Field<string>("value"))
.ToList();
RTESite.Value = RteValue[0];//set value for RTE from DB.
}
}
protected void submit_Click(object sender, EventArgs e)
{
string rootpath = HttpContext.Current.Server.MapPath("~/App_Data/NORTHWND.MDF");
string constr = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + rootpath + ";Integrated Security=True;Connect Timeout=30";
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("SELECT * FROM RTE WHERE Id = 1 UPDATE RTE SET value = @value", con);
con.Open();
cmd.Parameters.AddWithValue("@value", RTESite.Value); //update value of RTE to DB.
cmd.ExecuteNonQuery();
con.Close();
} |