How to disable a RangeSlider asp.net MVC razor c#? - rangeslider

Is there any built in property? I tried with different attributes like #readonly = "readonly" , #class = "disabledClass" and disabled="disabled", but I don't understand why it is not working.
Here is a piece of my code in razor:
#Html.EditorFor(model => model.olddata "RangeSlider", new {
id = "olddata",
minValue = 1,
maxValue = 10,
defaultValue = 6,
stepValue = 1
})

Related

Binding data source in kendo grid on mvc

First of all this is my first work using kendo ui. In work i have some data from database, i would like to replace my mvc webgrid into impressive kendo grid. I have created a list from database and iam trying to bind into kento grid. After setting data source. Still the grid remains empty.
public ActionResult Index()
{
SqlConnection sqcon = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand();
SqlDataAdapter sd = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
cmd.Connection = sqcon;
cmd.CommandText = "sps_selectemp";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
sqcon.Open();
sd.Fill(dt);
sqcon.Close();
List<EmployeeDetails> StudentList = new List<EmployeeDetails>();
foreach (DataRow dr in dt.Rows)
{
EmployeeDetails st = new EmployeeDetails();
st.ID = Convert.ToInt32(dr["EmpID"]);
st.FirstName = dr["FirstName"].ToString();
st.SecondName = dr["SecondName"].ToString();
st.Email = dr["Email"].ToString();
st.Gender = dr["Gender"].ToString();
st.Mobile = dr["Mobile"].ToString();
st.State = dr["State"].ToString();
st.City = dr["City"].ToString();
st.Country = dr["Country"].ToString();
StudentList.Add(st);
}
return View(StudentList.ToList());
}
Then i have added a view for corresponding view
#model List<webkendo.Models.EmployeeDetails>
#(Html.Kendo().Grid<webkendo.Models.EmployeeDetails>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.FirstName);
columns.Bound(c => c.SecondName);
columns.Bound(c => c.Email);
columns.Bound(c => c.Gender).Width(150);
})
.HtmlAttributes(new { style = "height: 550px;" })
.Scrollable()
.Groupable()
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("getusers", "Home"))
.PageSize(20)
)
)
Still tried different methods
public List<EmployeeDetails> getusers()
{
SqlConnection sqcon = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand();
SqlDataAdapter sd = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
cmd.Connection = sqcon;
cmd.CommandText = "sps_selectemp";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
sqcon.Open();
sd.Fill(dt);
sqcon.Close();
List<EmployeeDetails> StudentList = new List<EmployeeDetails>();
foreach (DataRow dr in dt.Rows)
{
EmployeeDetails st = new EmployeeDetails();
st.ID = Convert.ToInt32(dr["EmpID"]);
st.FirstName = dr["FirstName"].ToString();
st.SecondName = dr["SecondName"].ToString();
st.Email = dr["Email"].ToString();
st.Gender = dr["Gender"].ToString();
st.Mobile = dr["Mobile"].ToString();
st.State = dr["State"].ToString();
st.City = dr["City"].ToString();
st.Country = dr["Country"].ToString();
StudentList.Add(st);
}
return StudentList;
}
What am i doing wrong
First, decide if you are going to fetch all your data server side and present it in the grid, or if you are going to use AJAX with paging, etc. which is better for longer lists. You are trying to do both.
For the first, you need to get rid of the Read and set ServerOperation(false):
// Your model is the list of data
#(Html.Kendo().Grid(Model)
...
// Tell kendo you are providing the data
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.PageSize(20)
// No Read since you provide all the data up front
)
For the second option:
// Tell kendo the type you are going to fetch in the Read
#(Html.Kendo().Grid<EmployeeDetails>()
...
// Tell kendo you want data retrieved via AJAX
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("getusers", "Home"))
.PageSize(20)
)
Now create your read action to return JSON and take advantage of Kendo's DataSourceRequest that handles paging, filtering, sorting, etc.
public JsonResult getusers([DataSourceRequest] DataSourceRequest request)
{
// The AJAX generally works with IQueryables so that it can select a
// page full or records at a time. Entity Framework makes this easy.
// You would need to amend for ADO.NET with stored proc.
var employees = _db.Employees;
DataSourceResult response = employees.ToDataSourceResult(request);
return Json(response, JsonRequestBehavior.AllowGet);
}

From the view, can I get a SelectList's value and not its position in a DropDownList?

Let's say I've got a list of Employees with Employee IDs. In the Create View of the controller, I have:
public ActionResult Create()
{
ViewBag.EmployeeList= db.Employees.ToList().Select(x => new SelectListItem
{
Value = x.EmployeeID.ToString(),
Text = String.Format(x.FirstName + " " + x.LastName)
});
var quote = new Quote();
return View(quote);
}
(sidenote: I'm pretty sure I've implemented the SelectList inefficiently in my code by defining new SelectList again in the Create View)
Then in the Create View itself:
<div class="form-group">
#Html.LabelFor(model => model.EmployeeID, htmlAttributes: new { #class = "control-label col-md-4 employee-list" })
<div class="col-md-8">
#Html.DropDownListFor(model => model.EmployeeID, new SelectList(ViewBag.EmployeeList, "Value", "Text"), new { #class = "form-control employee-list" })
#Html.ValidationMessageFor(model => model.EmployeeID, "", new { #class = "text-danger" })
</div>
</div>
I want to write a JS/JQuery function that gets the value of EmployeeID when the selected Employee changes. At the moment this just gives me the option number:
$(document).ready(function () {
$('.employee-list').change(function () {
console.log($(this).val());
});
});
The purpose here is that I want to use the EmployeeID to populate another DropDownList field in the Create View, such as "Assign to Manager". A Manager would have a list of EmployeeIDs, and an EmployeeID could be assigned to multiple Managers. After selecting an Employee in the Create View, JS would be used to grab the EmployeeID, send it to the backend, query the Managers table for where it's found, return that list of Managers to the JS, and then plugged into the HTML of the page.
It's possible that a subset of the Employees would be used in the DropDownList, with, for example, EmployeeIDs of [3, 5, 11, 15], so I can't just subtract 1 from the option number to get the EmployeeID.
Oops, turns out I need to learn more about SQL.
I was seeding my SQL database with data like this:
context.Employees.AddOrUpdate(x => x.EmployeeID,
new DelegationApprover() { EmployeeID = 0, FirstName = "Eileen", LastName = "Dover" }
new DelegationApprover() { EmployeeID = 1, FirstName = "Wayne", LastName = "Carr" },
new DelegationApprover() { EmployeeID = 2, FirstName = "Richard", LastName = "Head" },
);
I thought I was setting the EmployeeIDs to start from 0, but SQL forces it to start from 1. I was working with the following data, thinking I was working with the former:
context.Employees.AddOrUpdate(x => x.EmployeeID,
new DelegationApprover() { EmployeeID = 1, FirstName = "Eileen", LastName = "Dover" }
new DelegationApprover() { EmployeeID = 2, FirstName = "Wayne", LastName = "Carr" },
new DelegationApprover() { EmployeeID = 3, FirstName = "Richard", LastName = "Head" },
);
When I checked($(this).val()) on Employee change, it looked like it was returning its option number and not the ID value. As it turns out, it was returning the value I wanted the entire time.

Edit value on mapping with AutoMapper

I'm trying to refactor my project and use automapper to map view model to entity model. Here is my my current code. I have used Guid.NewGuid(), GetValueOrDefault() and DateTime.Now. How can I edit those value on mapping?
var product = new Product
{
Id = Guid.NewGuid(),
Name = model.Name,
Price = model.Price.GetValueOrDefault(),
ShortDescription = model.ShortDescription,
FullDescription = model.FullDescription,
SEOUrl = model.SEOUrl,
MetaTitle = model.MetaTitle,
MetaKeywords = model.MetaKeywords,
MetaDescription = model.MetaDescription,
Published = model.Published,
DateAdded = DateTime.Now,
DateModified = DateTime.Now
};
then here is my map code
var config = new MapperConfiguration(cfg => {
cfg.CreateMap<Product, ProductCreateUpdateModel>().ReverseMap();
});
Tell me if I understood you right. You want to create AutoMapper configuration, but some of the properties you want to map manually? In this case, you can do following:
var config = new MapperConfiguration(cfg => {
cfg.CreateMap<Product, ProductCreateUpdateModel>()
.ReverseMap()
.ForMember(product => product.Price, expression => expression.MapFrom(model => model.Price.GetValueOrDefault()))
.ForMember(product => product.DateAdded, expression => expression.UseValue(DateTime.Now))
.ForMember(product => product.DateModified, expression => expression.UseValue(DateTime.Now));
});
If not, please, specify your question.

How to generate IEnumerable<SelectListItem> and set the Text property in controller/Edit CudtomerName and CustomerSurname

Does anyone knows how to generate IEnumerable and set the Text property in controller/Edit CudtomerName and CustomerSurname as shown below?
In Payment/Create controller I replace;
ViewBag.PaymentCustomer = new SelectList(db.CUSTOMERS, "CUSTID", "CustomerName");
with this:
ViewBag.PaymentCustomer = db.CUSTOMERS.ToList().Select(c => new SelectListItem
{
Value = c.CUSTID.ToString(),
Text = string.Format("{0} {1}", c.CustomerName, c.CustomerSurname)
});
and its working. But in Payment/Edit is:
ViewBag.PaymentCustomer = new SelectList(db.CUSTOMERS, "CUSTID", "CustomerName", pAYMENT.PaymentCustomer);
Both ViewBag.PaymentCustomer looks same. The Payment/Edit its also get 4th parameter as "pAYMENT.PaymentCustomer". I cannot use "pAYMENT.PaymentCustomer" in db.CUSTOMERS.ToList().Select...
I try this:
//ViewBag.PaymentCustomer = new SelectList(db.CUSTOMERS, "CUSTID", "CustomerName", pAYMENT.PaymentCustomer);
ViewBag.PaymentCustomer = new SelectList(db.CUSTOMERS.ToList().Select(c => new SelectListItem
{
Value = c.CUSTID.ToString(),
Text = string.Format("{0} {1}", c.CustomerName, c.CustomerSurname)
}), pAYMENT.PaymentCustomer);
And After build and run. I can see dropdown list and inside drop down list does not shows Customername and CustomerSurname. It shows "System.Web.Mvc.SelectListItem".
How do I do that?
If u want to generate IEnumerable<SelectListItem> means Just visit the following link it will helpful for u
Asp.Net MVC with Drop Down List, and SelectListItem Assistance
http://codeclimber.net.nz/archive/2009/08/05/how-to-create-a-dropdownlist-with-asp.net-mvc.aspx
ViewBag.CustomerList = new SelectList(db.CUSTOMERS.ToList().Select(c => new SelectListItem {
Value = c.CUSTID.ToString(),
Text = string.Format("{0} {1}", c.CustomerName, c.CustomerSurname),
}), "Value", "Text", pAYMENT.PaymentCustomer);

Searching with ID NO subsonic

public List<EmployeeDirectory> employee = new Health_Scheme_SystemDB.Select
.From<EmployeeDirectory>()
.Where(EmployeeDirectoryTable.ID_NOColumn).Contains(1005)
.ExecuteTypedList<EmployeeDirectory>();
The .Select is giving me problems. Its saying that 'Health_Scheme_System.Health_Scheme_SystemDB.Select' is a 'property' but is used like a 'type'
Remove the new - you are not creating a new instance so you shouldn't use new.
public List<EmployeesX> GetID(string IDNO)
{
Health_Scheme_System.Health_Scheme_SystemDB db = new Health_Scheme_System.Health_Scheme_SystemDB();
var d = (from c in db.EmployeeDirectories
where c.ID_NO.Contains(IDNO)
select new EmployeesX { ID_NO = c.ID_NO, FIRST_NAME = c.FIRST_NAME, LAST_NAME = c.LAST_NAME, EMPLOYMENT_DATE = ((DateTime)c.EMPLOYMENT_DATE).Date, TERMINATION_DATE = ((DateTime)c.TERMINATION_DATE).Date, LOCATION_CODE = c.LOCATION_CODE });
return d.ToList<EmployeesX>();
}
Then bind the grid view with this code. obviously there the data input in the textbox only will be displayed in the gridview.
gvView.DataSource = da.GetID(txtIDNO.Text);
gvView.DataBind();

Resources