need help: editor and numbers asp.net - asp.net-mvc

I have an editor field in asp.net which needs to be integer input only between 1 and the size of a list. Atm i got this as code
#Html.Editor("Prioriteit" + item, new { htmlAttributes = new { #type = "number", min = "0",step = "1", value = "0" } })
this isn't to the maximum of the list, I know this. However when i open the page i can still add text.
View with text in editor
Someone can help me out?
thanks in advance
Changed the code for the sake of someone linking it to another question
code
#Html.TextBox("Prioriteit" + item,null, new { htmlAttributes = new { #type = "number", min = "0",step = "1", value = "0" } })
still the same
`

You can also do the following:
<input type="number" min="0" step="1" value="0" name="Prioriteit#item" />

Try this:
#Html.TextBox("Prioriteit" + item, "0", new { #type="number", min = "0", step = "1" })

Related

How to binding `ngx-intl-tel-input` with only "internationalNumber"

I'm use ngx-intl-tel-input, when binding have model with:
"phone":
{
"countryCode": "",
"dialCode": "",
"internationalNumber": "",
"nationalNumber": "",
"number": ""
}
but I want model:
"phone":
{
"internationalNumber": ""
}
what can I do?
Thank you very much!
you can have middleware variable for the binding :
<ngx-intl-tel-input [(ngModel)]="mobile"> <ngx-intl-tel-input>
for example:-
let mobile;
let internationalNumber="";
internationalNumber=mobile.internationalNumber;
now your binding is ready!
[(ngModel)] actually comes with event binding and property binding. Below two lines are equal.
<input [ngModel]="yourVariable" (ngModelChange)="yourVariable = $event">
and
<input [(ngModel)]="yourVariable">
So for your question, you can do something like below.
<input [ngModel]="yourVariable" (ngModelChange)="yourVariable = $event.internationalNumber">

Set date from model, not default by datetimepicker

Have a good day. I'm searching the way to set date from edit view in my app and only shows the current date.
I'm using bootstrap datetimepicker like this:
$('.datepicker').datetimepicker(
{
format: 'DD/MM/YYYY',
locale: 'es',
icons: {
time: "fas fa-clock",
date: "fas fa-calendar-alt",
up: "fas fa-arrow-up",
down: "fas fa-arrow-down",
previous: "fas fa-chevron-left",
next: "fas fa-chevron-right"
},
defaultDate: null,
daysOfWeekDisabled: [0, 6]
});
and in my form I've implemented as:
#Html.EditorFor(model => model.ApplyDate, new { htmlAttributes = new { #class = "form-control datepicker", placeholder = "dd/mm/yyyy", tabindex = "5", maxlength = "10", required = "", #Value = Model.ApplyDate } })
but not getting any good results. Only current date is set.
Thanks.
I've just realized that my problem setting default date was cause I've used the disabled dates property:
daysOfWeekDisabled: [0, 6]
Once I've take off that part, my problem was solved. Hope to help someone

Filling out Html.DropDownListFor from csv file in Umbraco

My drop down list is filled out like this at the moment and interacts with my model employeeModel:
#Html.DropDownListFor(x => employeeModel.JobTitle,
new SelectList(
new List<Object>
{
new { value = "Job Title 1", text = "Job Title 1"},
new { value = "Job Title 2", text = "Job Title 2"},
new { value = "Job Title 3", text = "Job Title 3"},
new { value = "Job Title 4", text = "Job Title 4"}
},
"value",
"text",
0), "Select...", new { #class = "form-control" })
However, I need a way to so that I can fill this out way more easily than having to either manually do this by hand. The easiest way I thought of doing this was through a CSV file. However, I have no clue as to how I can get my user to upload the file, then grab all the contents of it so that it can fill the above code snippet.
Has anyone ever done such a thing before?
You could add an Upload field where the user could select a text file containing the list of jobs. In this case I'm assuming that the file looks something like this:
Job Title 1
Job Title 2
Job Title 3
Job Title 4
Job Title 5
In your controller you'd have to get the property value and convert it from a relative Uri path to an absolute file path. Then use StreamReader to read through the file and add the items to a list, before using the values to create a list of SelectListItems and add them to your employeeModel.
var fileUri = CurrentPage.GetPropertyValue<string>("jobFile");
var filePath = System.Web.HttpContext.Current.Server.MapPath(fileUri);
var values = new List<string>();
using (var reader = new StreamReader(filePath))
{
values = reader.ReadToEnd().Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList();
}
employeeModel.Jobs = values.Select(x =>
{
return new SelectListItem
{
Value = x,
Text = x
};
});
Finally, render the drop down list in your view:
#Html.DropDownListFor(x => x.JobTitle, Model.Jobs, "Select...", new { #class = "form-control" })

.NET Kendo Scheduler: dynamically change datasource resources

Now i'm using a datasource like this: (with the parameters to filter hard coded)
$(function () {
$("#scheduler").kendoScheduler({
date: new Date(Date.now()),
startTime: new Date(2013, 5, 13, 9, 0, 0, 0),
height: 800,
timezone: "Etc/UTC",
group: {
resources: ["Rooms"]
},
resources: [
{
name:"Rooms",
title: "Room",
field: "RoomID",
dataSource: {
transport:
{
read: { url: "#Html.Raw(Url.Action("Filter_Rooms", "Room", new{
pPar1= true,
pPar2 = false,
pPar3 = true,
}))", dataType: "json" }
}
}
}
As you can see these paramaters are still hard coded and I want to change them whenever the user wants using checkboxes:
<div class="checkbox">
<label>
<input id="chkPar1" type="checkbox"> Parameter 1
</label>
</div>
<div class="checkbox">
<label>
<input id="chkPar2" type="checkbox"> Parameter 2
</label>
</div>
Filter
I thought while using javascript to check if button is clicked and then store checkbox paramaters in global variables and use these in the transport read of the scheduler but it seems you can't use document.getelementbyId here.
Here they suggested Kendo UI Dynamically Change Datasource String (XML) but that doesn't seem to work for me neither..
var dynamicUrl = "Html.Raw(Url.Action('Filter_Rooms', 'Room', new{pFilter = true, pCapacity = 25,pBeamer = true,pTelevision = false}))', dataType: 'json'"
var scheduler = $("#scheduler").data("kendoScheduler");
scheduler.dataSource.transport.options.read.url = dynamicUrl;
So How can I dynamically change these paramaters or update the entire transport read url?
Regards
Try this:
var pFilter = (document.getElementById("someID").value);
var pCapacity = document.getElementById("someID").value;
var pBeamer = document.getElementById("someID").value;
var pTelevision = document.getElementById("someID").value;
var dynamicUrl = "Html.Raw(Url.Action('Filter_Rooms', 'Room', new{pFilter = " + pFilter + ", pCapacity = " + pCapacity + ",pBeamer = " + pBeamer + ",pTelevision = " + pTelevision + "}))', dataType: 'json'"
There could be some type of string format that you could use like in C# but I'm not sure. Hope this works!
Not sure if it's exactly what you're after, but a good frame of reference might be this example project. It very simply shows how to load new content when you change the view. You may be able to adapt it.

Html Helper with special htmlattributes

Does anyone know how to pass html attributes like "data-date" to the Html.TextBox()??
It is used from the bootstrap datepicker.
Is there a way around it?
#Html.TextBoxFor(p => p.DateFrom, new { #class = "small", type = "date", "data-date"="12-02-2012" })
You have to use underscore instead of '-'.
So what you're after would go something like this:
#Html.TextBoxFor(p => p.DateFrom, new { #class = "small", #type = "date", #data_date="12-02-2012" })
Use:
new Dictionary<string, object> { { "class", "small" }, {"type", "date"} { "data-date", "12-02-2012" } }
instead of:
new { #class = "small", type = "date", "data-date"="12-02-2012" }
I was trying to add the date picker to the Html helper using bootstrap. rudeovski ze bear's answer made it easier.
This is how it worked for me.
#Html.TextBox("startdate", null
, new {#class = "type", #type = "date", #data_date="12-02-2012" })

Resources