Answer the question
In order to leave comments, you need to log in
How to get data out of database and change save again?
Good time again!
Tell me this time this:
I have a project on asp.net mvc 4 with a working database that is spinning on sqlexpress 2014. Thank God the database works from the project, it gives out the edited data and saves it back.
My problem is this:
There will be about 50 bases in the admin panel, I will make a separate view for each. But I want to make a datagrid so that data would go into it, for example, create a new row, save it. And I want to do this whole thing, about how to do it here: An example of what you want , but alas, I don’t understand how to attach a specific table from the database to jquery and output with saving.
Poke me again in the solution of this quest, please !!!!
Answer the question
In order to leave comments, you need to log in
The link you provided has the following code:
var grid, dialog;
grid = $('#grid').grid({
// ваш url, который будет передавать данные из вашей бд
dataSource: '/Grid/GetPlayers',
uiLibrary: 'bootstrap',
// имена полей, которые следует выводить в таблице
columns: [
{ field: 'ID', width: 32 },
{ field: 'Name', sortable: true },
{ field: 'PlaceOfBirth', title: 'Place Of Birth', sortable: true }
],
pager: { limit: 5, sizes: [2, 5, 10, 20] }
});
[HttpPost]
public JsonResult GetAccounts(int page, int limit)
{
using (var context = new Database1Entities())
{
// получаем записи для указанной страницы
var result = context.Account.OrderBy(
row => row.AccountID
).Skip((page - 1) * limit).Take(limit).ToArray();
int total = context.Account.Count();
// возвращаем json
return Json(new { records = result, total = total });
}
}
grid = $('#grid').grid({
// ссылка на действие GetAccounts в контроллере Home
// запрос выполняется методом POST
dataSource: { url: '/Home/GetAccounts', method: 'POST' },
uiLibrary: 'bootstrap',
columns: [
{ field: 'AccountID', sortable: true },
{ field: 'FirstName', sortable: true },
{ field: 'LastName', sortable: true },
{ field: 'Company', sortable: true },
{ field: 'Position', sortable: true }
],
pager: { limit: 2, sizes: [2, 5, 10, 20] }
});
Good time, Alexey Nemiro Alexey Nemiro !
The model for the database is:
-------------------------------------
using System.Data.Entity;
namespace ......Areas.Auth.Models
{
public class RWOnlineDb : DbContext
{
public DbSet AccountModel { get; set; }
}
}
------------------------------------
The data in the database is:
------ -----------------------------
using System.Collections.Generic;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace .................Areas.Auth.Models
{
public class AccountModel
{
[Key]
public int AccountID { get; set; }
[Display(Name = "Email")]
[Required(ErrorMessage = "Email not specified")]
public string Email { get; set; }
[Display(Name = "Login")]
[Required(ErrorMessage = "Login not specified")]
public string Username { get; set; }
[Display(Name = "Password")]
[Required(ErrorMessage = "Please provide a password")]
[DataType(DataType.Password)]
public string Password { get; set; }
[Display(Name = "Repeat Password")]
[Compare("Password",
[DataType(DataType.Password)]
public string ConfirmPassword { get; set; }
[Display(Name = "Last name")]
[Required(ErrorMessage = "Name not specified")]
public string LastName { get; set; }
[Display(Name = "First name")]
[Required(ErrorMessage = "Last name not specified")]
public string FirstName { get; set; }
[Display(Name = "Company")]
[Required(ErrorMessage = "No name provided")]
public string Company { get; set; }
[Display(Name = "Position")]
[Required(ErrorMessage = "No name provided")]
public string Position { get; set;
[Required(ErrorMessage = "No phone specified")]
public string Phone { get; set; }
[DisplayName("Postal code")]
public string Zip { get; set; }
[DisplayName("Region")]
public string State { get; set; }
[DisplayName("City")]
public string City { get; set; }
[DisplayName("Address")]
public string Address { get; set; }
}
}
----------------------------------------------------- -----
But I don't understand how to set the path to the
dataSource database: '/Grid/GetPlayers', ----- what is it?
Thank you in advance...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question