如何使用html在教科书中显示会话值 [英] how to display the session value in text book using html
本文介绍了如何使用html在教科书中显示会话值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在html中将会话值附加到文本框中请帮帮我。我正在获得会话的价值,但如何将其分配给html中的文本框我想根据下面的id显示名称是代码..
用于显示名称的控制器类根据id
how to append a session value to a textbox in html please help me out. I am getting the value into the session but how assign it to a textbox in html i want to display the name according to the id below is the code..
Controller Class for displaying Name According to the id
[HttpGet]
public ActionResult GetDetailsById()
{
BusinessEntities be = new BusinessEntities();
return View(be);
}
[HttpPost]
public ActionResult DetailsById(FormCollection fc)
{
BusinessEntities be = new BusinessEntities();
be.id =Convert.ToInt32( fc["id"]);
DataAceessLayer dal = new DataAceessLayer();
dal.GetDetails(be);
TempData["Name"] = be.name1;
return View(test1());
}
控制器的数据访问层
Data Acess Layer for the controller
public void GetDetails(BusinessEntities be)
{
//string name;
be.name1 = HttpContext.Current.Session.ToString();
be.gender1 = HttpContext.Current.Session.ToString();
be.course1 = HttpContext.Current.Session.ToString();
be.grade1 = HttpContext.Current.Session.ToString();
using(SqlConnection con=new SqlConnection(GlobalConnection.connection))
{
con.Open();
SqlCommand cmd = new SqlCommand("GETDETAILSBYID", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", be.id);
SqlDataReader dr = cmd.ExecuteReader();
if(dr.HasRows)
{
while(dr.Read())
{
//be.id = Convert.ToInt32( dr["id"].ToString());
be.name1 = dr["name"].ToString();
be.gender1 = dr["gender"].ToString();
be.course1 = dr["course"].ToString();
be.grade1 = dr["grade"].ToString();
}
}
}
查看此内容:
view for this:
<body>
@using (Html.BeginForm("DetailsById", "EmployeeController", FormMethod.Post))
{
if(Session["name"]==null)
{
<table>
<tr>
<td>Id</td>
<td>
<input type="text" name="txtid" id="txtid" required />
</td>
</tr>
<tr>
<td>Name</td>
<td>
<input type="text" name="txtname" id="txtname" value="@TempData["Name"]" required />
</td>
</tr>
<tr>
<td>Gender</td>
<td>
<input type="text" name="txtgender" id="txtgender" value="@Model.gender" required />
</td>
</tr>
<tr>
<td>Course</td>
<td>
<input type="text" name="txtcourse" id="txtcourse" value="@Model.course" required />
</td>
</tr>
<tr>
<td>grade</td>
<td>
<input type="text" name="txtngrade" id="txtgrade" value="@Model.grade" required />
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="GetDetails" id="btnGetDetails" onclick="GetDetails()" />
</td>
</tr>
<tr>
<td>
<input type="hidden" id="txthidden" name="txthidden" value="@Model.name1" />
</td>
</tr>
</table>
}
}
<script type="text/javascript">
function GetDetails() {
if($("#btnGetDetails").val()=="GetDetails")
{
$.ajax({
type: 'post',
url: '@Url.Action("DetailsById")',
data: {
id: $("#txtid").val(),
},
datatype: 'json',
success: function (data) {
$("#txtname").val() = @TempData["Name"].ToString();
}
})
}
}
</script>
请高兴我想根据会话值
Please HElp me i want to append and dispaly the name according to the session value
推荐答案
( #btnGetDetails)。val()== < span class =code-string> GetDetails)
{
("#btnGetDetails").val()=="GetDetails") {
.ajax({
type:' post',
url:' @ Url.Action(DetailsById)',
数据:{
id:
.ajax({ type: 'post', url: '@Url.Action("DetailsById")', data: { id:
( #txtid)。val(),
},
数据类型:' json',
成功:功能(数据){
("#txtid").val(), }, datatype: 'json', success: function (data) {
这篇关于如何使用html在教科书中显示会话值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文