Jquery =>model.IsActive,htmlAttributes:new{@class=“control label col-md-2”}) @EditorFor(model=>model.IsActive,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.IsActive,“,new{@class=“text danger”}) @LabelFor(model=>model.CreatedBy,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.CreatedBy,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.CreatedBy,“,new{@class=“text danger”}) }
我找到了答案,我认为只是一些小错误,我只是在我的ajax中替换了两行代码,在我的控制器中替换了我的控制器。我只是返回了视图而不是部分视图,对于传递id,我只是使用了不同的方法 这是我的工作代码,我不知道为什么我的模态在作为部分视图传递时消失了,这仍然是一个疑问 index.cshtmlJquery =>model.IsActive,htmlAttributes:new{@class=“control label col-md-2”}) @EditorFor(model=>model.IsActive,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.IsActive,“,new{@class=“text danger”}) @LabelFor(model=>model.CreatedBy,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.CreatedBy,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.CreatedBy,“,new{@class=“text danger”}) },jquery,asp.net-mvc,dapper,Jquery,Asp.net Mvc,Dapper,我找到了答案,我认为只是一些小错误,我只是在我的ajax中替换了两行代码,在我的控制器中替换了我的控制器。我只是返回了视图而不是部分视图,对于传递id,我只是使用了不同的方法 这是我的工作代码,我不知道为什么我的模态在作为部分视图传递时消失了,这仍然是一个疑问 index.cshtml $(document).on('click', '.edit', function () { var studentId = $(this).closest('t
$(document).on('click', '.edit', function () {
var studentId = $(this).closest('tr').find('td:eq(1)').text();
$.get('/Student/AddEditEmployee?studentId=' + studentId, function (data) {
//set Modal header text
// $("#ModalHeader").html("Edit");
//add returned partial view html into modal body
$("#myModalBodyDiv1").html(data);
//show modal
$('#myModal1').modal('show');
//inititae jQuery validation
// $("#BlogForm").validate();
});
});
控制器代码
[HttpGet]
public ActionResult AddEditEmployee(int studentId)
{
Student student = new Student();
using (MySqlConnection db = new MySqlConnection(ConfigurationManager.ConnectionStrings["Constr"].ConnectionString))
{
student = db.Query<Student>("Select * From student " +
"WHERE studentid =" + studentId, new { studentId }).SingleOrDefault();
}
return View("AddEditEmployee", student);
}
[HttpGet]
公共行动结果增编员工(国际学生ID)
{
学生=新生();
使用(MySqlConnection db=newmysqlconnection(ConfigurationManager.ConnectionStrings[“Constr”].ConnectionString))
{
student=db.Query(“选择*自student”+
“WHERE studentid=“+studentid,new{studentid}).SingleOrDefault();
}
返回视图(“AddedEmployee”,学生);
}
你没有写完整的问题,编辑你的问题,然后写下你需要说的话{但我一点击}……@Ali我编辑了我的问题,很抱歉我没有写完整的问题,但你能帮我解决问题吗?猜你已经找到解决办法了:)
@model DapperDemo.Models.Student
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.StudentId)
<div class="form-group">
@Html.LabelFor(model => model.BatchId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.BatchId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.BatchId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.StudentName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.StudentName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.StudentName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.RollNumber, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.RollNumber, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.RollNumber, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ContactNumber, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ContactNumber, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ContactNumber, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ParentContactOne, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ParentContactOne, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ParentContactOne, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ParentContactSecond, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ParentContactSecond, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ParentContactSecond, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.IsActive, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.IsActive, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.IsActive, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CreatedBy, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CreatedBy, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CreatedBy, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Update" class="btn btn-default" />
</div>
</div>
</div>
}
$(document).on('click', '.edit', function () {
var studentId = $(this).closest('tr').find('td:eq(1)').text();
$.get('/Student/AddEditEmployee?studentId=' + studentId, function (data) {
//set Modal header text
// $("#ModalHeader").html("Edit");
//add returned partial view html into modal body
$("#myModalBodyDiv1").html(data);
//show modal
$('#myModal1').modal('show');
//inititae jQuery validation
// $("#BlogForm").validate();
});
});
[HttpGet]
public ActionResult AddEditEmployee(int studentId)
{
Student student = new Student();
using (MySqlConnection db = new MySqlConnection(ConfigurationManager.ConnectionStrings["Constr"].ConnectionString))
{
student = db.Query<Student>("Select * From student " +
"WHERE studentid =" + studentId, new { studentId }).SingleOrDefault();
}
return View("AddEditEmployee", student);
}