Я не могу написать какой-либо контент в своем текстовом поле моего столбца веб-сетки. Пожалуйста, предложите, как я могу добиться этого, вот мой HTML-код
@model IEnumerable<Sampletestapp.Data.UserInfo>
@{
ViewBag.Title = "Test";
Layout = "~/Views/Shared/_Layout.cshtml";
WebGrid webGrid = new WebGrid(source: Model, canSort: false, canPage: false);
}
<h2>Test</h2>
<style type="text/css">
body {
font-family: Arial;
font-size: 10pt;
}
table {
border: 1px solid #ccc;
border-collapse: collapse;
background-color: #fff;
}
table th {
background-color: #B8DBFD;
color: #333;
font-weight: bold;
}
table th, table td {
padding: 5px;
border: 1px solid #ccc;
}
table, table table td {
border: 0px solid #ccc;
}
.Pager span {
text-align: center;
color: #333;
display: inline-block;
width: 20px;
background-color: #B8DBFD;
margin-right: 3px;
line-height: 150%;
border: 1px solid #B8DBFD;
}
.Pager a {
text-align: center;
display: inline-block;
width: 20px;
background-color: #ccc;
color: #333;
border: 1px solid #ccc;
margin-right: 3px;
line-height: 150%;
text-decoration: none;
}
</style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$("#btnSave").click(function () {
$.ajax(
{
type: "POST", //HTTP POST Method
url: "Home/Test", // Controller/View
data: { //Passing data
Username: $("#Username").val(), //Reading text box values using Jquery
Password: $("#Password").val(),
Name: $("#Name").val(),
City: $("#City").val(),
Country: $("#Country").val(),
ContactNo: $("#ContactNo").val(),
Gender: $("#Gender").val(),
PDS: $("#PDS").val()
}
});
});
</script>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>UserInfo</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.Label("Username", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBox("Username", "", new { @class = "form-control" })
@Html.ValidationMessage("Username", "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.Label("Password", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBox("Password", "", new { @class = "form-control" })
@Html.ValidationMessage("Password", "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.Label("Name", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBox("Name", "", new { @class = "form-control" })
@Html.ValidationMessage("Name", "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.Label("Lastname", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBox("Lastname", "", new { @class = "form-control" })
@Html.ValidationMessage("Lastname", "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.Label("City", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("City", new SelectList(ViewBag.City, "CityId", "Cityname", "Cityname"))
@Html.ValidationMessage("City", "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.Label("Country", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("Country", new SelectList(ViewBag.Country, "CountryId", "Countryname", "Countryname"))
@Html.ValidationMessage("Country", "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.Label("ContactNo", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBox("ContactNo", "", new { @class = "form-control" })
@Html.ValidationMessage("ContactNo", "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.Label("Gender", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
Gender:
Male @Html.RadioButton("Gender", "Male")
Female @Html.RadioButton("Gender", "Female")
@Html.ValidationMessage("Gender", "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.Label("PDS", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBox("PDS", "", new { @class = "form-control" })
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input id="btnSave" type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
</div>
}
@webGrid.GetHtml(
htmlAttributes: new { @id = "WebGrid", @class = "Grid" },
columns: webGrid.Columns(
webGrid.Column("Id", "Id"),
webGrid.Column("Name", "Name"),
webGrid.Column("Lastname", "Lastname"),
webGrid.Column("City", "City"),
webGrid.Column("Country", "Country"),
webGrid.Column("PDS", "PDS"),
webGrid.Column("Days",
style: "col5",
format: @<text>
<span id="day"></span>
<input type="text" id="txtval" class="edit" />
</text>))
)
<br />
<div class="Pager"></div>
<script src="~/Scripts/ASPSnippets_Pager.min.js"></script>
<script type="text/javascript">
$(function () {
GetUsers(1);
//$('.edit-mode').hide();
$('.edit-Days').on('click', function () {
var tr = $(this).parents('tr:first');
tr.find('.edit-mode, .display-mode').toggle();
});
});
function GetUsers(pageIndex) {
$.ajax({
type: "POST",
url: "/Home/AjaxMethod",
data: '{pageIndex: ' + pageIndex + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: function (jqXHR, textStatus, errorThrown) {
console.log("Custom error : " + jqXHR.responseText + " Status: " + textStatus + " Http error:" + errorThrown);
}
});
};
//your code here
function OnSuccess(response) {
var model = response;
var row = $("#WebGrid tbody tr:last-child").clone(true);
$("#WebGrid tbody tr").remove();
$.each(model.users, function () {
var user = this;
$("td", row).eq(0).html(user.Id);
$("td", row).eq(1).html(user.Name);
$("td", row).eq(2).html(user.Lastname);
$("td", row).eq(3).html(user.City);
$("td", row).eq(4).html(user.Country);
$("td", row).eq(5).html(user.PDS);
$("#WebGrid").append(row);
row = $("#WebGrid tbody tr:last-child").clone(true);
});
$(".Pager").ASPSnippets_Pager({
ActiveCssClass: "current",
PagerCssClass: "pager",
PageIndex: 1,
PageSize: 5,
RecordCount: model.RecordCount
});
}
, а вот мой код контроллера
public ActionResult Test()
{
ViewBag.Country = from result in db.tblcountries select result;
ViewBag.City = from result in db.tblcities select result;
List<UserInfo> dummy = new List<UserInfo>();
dummy.Add(new UserInfo());
return View(dummy);
}
[HttpPost]
public JsonResult AjaxMethod(int pageIndex)
{
Users usermodel = new Users();
usermodel.PageIndex = pageIndex;
usermodel.PageSize = 10;
usermodel.RecordCount = db.UserInfoes.Count();
int startIndex = (pageIndex - 1) * usermodel.PageSize;
db.Configuration.ProxyCreationEnabled = false;
usermodel.users = (from items in db.UserInfoes
select items)
.OrderBy(items => items.Id).Skip(startIndex)
.Take(usermodel.PageSize).ToList();
return Json(usermodel);
}