Asp.net MVC Checkbox binding with string format - asp.net-mvc

<div class="form-group">
<label>Quoted With New Combo Endorsement</label>
#Html.DropDownListFor(a => a.Quoted_With_New_Combo_Endorsement, new[]
{
new SelectListItem {Text = "Yes", Value = "Yes"},
new SelectListItem {Text = "No", Value = "No"},
}, "Select the Value", new { style = "width:250px", #class = "form-control" })
</div>
How to convert this code to the checkbox for(Yes/NO)?
Reminder: datatype can't be changed to bool

I've done this in a project and it's working fine.
<div class="form-group">
<label class="col-md-2 control-label">Scan in Colour?</label>
<div class="col-md-10">
<div class="radio-group">
#Html.RadioButtonFor(m => m.ScanInColour, "Yes",
new { #id = "ScanInColourYes", #class = "form-control" })
<span>Yes</span>
#Html.RadioButtonFor(m => m.ScanInColour, "No",
new { #id = "ScanInColourNo", #class = "form-control" })
<span>No</span>
</div>
</div>
</div>

Shouldn't it be a radio-button because it either yes or no?
Instead of the #Html.DropDownListFor use:
#Html.RadioButton("YesNo","Yes")
#Html.RadioButton("YesNo","No")

Related

How Can I add a dollar symbol in ASP.NET MVC5?

How do I add a dollar symbol in front of a TextBox, which cannot be edited? I want to have the dollar symbol so people don't need to type '$' by themselves. Here is my code:
#Html.Label("lblP1", "Rate 1", htmlAttributes: new { #class = "control-label", #style = "margin-right: 30px" })
<br />
#Html.EditorFor(m => m.Pricing.Price1, null, new { htmlAttributes = new { #type = "string", #class = "form-control" } })
This is an example using bootstrap:
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">$</span>
</div>
#Html.EditorFor(m => m.Pricing.Price1, null, new { htmlAttributes = new { #type = "string", #class = "form-control" } })
</div>
Source: https://getbootstrap.com/docs/4.0/components/input-group/

Want to generate dynamic control with complete styling

Hi I want to have add more button on my page which can replicate the existing form as many times as i want as i click add more button just like what linkedin is doing for education and experience section.
I want dynamic controls with complete styling
<div class="form-horizontal" style=" border: 1px solid #c6c7cc;
border-radius: 5px;
font: 14px/1.4 " helvetica="" neue",="" helvetica,="" arial,="" sans-serif;="" overflow:="" hidden;="" width:="" 840px;="" padding:="" 10px;="" background-color:="" white;"="">
<div class="row">
<div class="col-lg-12">
<h4 style="background-color:cornflowerblue; padding:5px;">Educational information</h4>
</div>
</div>
<div style="margin:10px;">
<div class="row">
<div class="col">
#Html.EditorFor(model => model.educations.Degree_Title, new { htmlAttributes = new { placeholder = "Enter Degree Title ", #class = "form-control" } })
#Html.ValidationMessageFor(model => model.educations.Degree_Title, "", new { #class = "text-danger" })
</div>
<div class="col">
#Html.EditorFor(model => model.educations.School, new { htmlAttributes = new { placeholder = "Enter School Name", #class = "form-control" } })
#Html.ValidationMessageFor(model => model.educations.School, "", new { #class = "text-danger" })
</div>
</div>
</div>
<div style="margin:10px;">
<div class="row">
<div class="col">
#Html.EditorFor(model => model.educations.Field_of_study, new { htmlAttributes = new { placeholder = "Enter Field of Study", #class = "form-control" } })
#Html.ValidationMessageFor(model => model.educations.Field_of_study, "", new { #class = "text-danger" })
</div>
<div class="col">
#Html.EditorFor(model => model.educations.Description, new { htmlAttributes = new { placeholder = "Enter Course/Degree Detail", #class = "form-control" } })
#Html.ValidationMessageFor(model => model.educations.Description, "", new { #class = "text-danger" })
</div>
</div>
</div>
<div style="margin:10px;">
<div class="row">
<div class="col">
#Html.DropDownListFor(model=>model.educations.Grade, new List<SelectListItem>
{
new SelectListItem{ Text="Select Grade", Value = "1" },
new SelectListItem{ Text="A", Value = "2" },
new SelectListItem{ Text="B", Value = "3" },
new SelectListItem{ Text="C", Value = "4" },
new SelectListItem{ Text="D", Value = "5" },
new SelectListItem{ Text="E", Value = "6" },
}, new { #class = "btn form-text" })
#Html.ValidationMessageFor(model => model.educations.Grade, "", new { #class = "text-danger" })
<div class="col-sm-4">
#Html.EditorFor(model => model.educations.Start_Year, new { htmlAttributes = new { placeholder = "Enter Start Date", #class = "form-control" } })
#Html.ValidationMessageFor(model => model.educations.Start_Year, "", new { #class = "text-danger" })
</div>
<div class="col-sm-4">
#Html.EditorFor(model => model.educations.End_Year, new { htmlAttributes = new { placeholder = "Enter End Date", #class = "form-control" } })
#Html.ValidationMessageFor(model => model.educations.End_Year, "", new { #class = "text-danger" })
</div>
<div class="col">
<label for="switch17">Active</label>
#Html.CheckBoxFor(m => m.educations.isFinalDegree, new { id = "switch17", name = "switch17", #class = "css-checkbox9 all_check" })
</div>
</div>
</div>
</div>
</div>
it should generate the above complete code as many times as i click the button

How to populate dropdown list base on another?

View:
<div class="form-group">
<label for="country" class="control-label col-lg-5">#Html.Label(#BetXOnline.TranslationProvider.Instance.GetTranslationMessage("COUNTRY")):#Html.ValidationMessageFor(m => m.Register.SelectCountryId, null, new { #class = "required" })</label>
<div class="col-lg-7">
#Html.DropDownListFor(m => m.Register.SelectCountryId, Model.Register.Country, "Select country", new { id = "country", #class = "form-control" })
</div>
</div>
<!-- Region-->
<div class="form-group">
<label for="region" class="control-label col-lg-5">#Html.Label(#BetXOnline.TranslationProvider.Instance.GetTranslationMessage("REGION")):#Html.ValidationMessageFor(m => m.Register.SelectRegionId, null, new { #class = "required" })</label>
<div class="col-lg-7">
#Html.DropDownListFor(m => m.Register.SelectRegionId, Model.Register.Region, "Select region", new { id = "region", #class = "form-control" })
</div>
</div>
<!-- City-->
<div class="form-group">
<label for="region" class="control-label col-lg-5">#Html.Label(#BetXOnline.TranslationProvider.Instance.GetTranslationMessage("CITY")):#Html.ValidationMessageFor(m => m.Register.SelectCityId, null, new { #class = "required" })</label>
<div class="col-lg-7">
#Html.DropDownListFor(m => m.Register.SelectCityId, Model.Register.City, "Select region", new { id = "region", #class = "form-control" })
</div>
</div>
Controller:
model.Register.Country = new SelectList(manager.GetCountries(), "Id", "Name");
model.Register.Region = new SelectList(manager.GetRegions(model.Register.SelectCountryId), "Id", "Name");
model.Register.WebTypeOfLicense = new SelectList(CommonDbService.GetAllLicense(), "Id", "Name");
model.Register.City = new SelectList(manager.GetCities(model.Register.SelectRegionId), "Id", "Name");
Function:
IEnumerable<ICountry> GetAllCountries();
ICountry GetCountry(int countryId);
IEnumerable<IRegion> GetRegions(int countryId);
IRegion GetRegion(int regionId);
IEnumerable<ICity> GetCities(int regionId);
ICity GetCity(int cityId);
Main idea is when i select country to get state and when i click on state to get cities...State recives id of country so i need to populate state with id of country to get states and then cites recive id of state to populate cities
You need some javascript function that will fire on dropdown change event and bring the respective child element of selected parent in dropdown. once you receive response fill the child dropdown with latest value you have.
one of simple example : sample

Select field in form

I am using a form like this, how can I change the textboxforinto a select, because I can't find any option to do it in the #Html
#using (Html.BeginForm("LeggTilUtdannelse", "Utdannelse", FormMethod.Post, new { #class = "form-horizontal", id = "legg-til-form" }))
{
#Html.AntiForgeryToken()
<div class="form-group">
#Html.LabelFor(m => m.Til, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.TextBoxFor(m => m.Til, new { #class = "form-control", autocomplete = "off" })
</div>
</div>
}
I think you're looking for an #Html.DropDownList or #Html.DropDownListFor.

Searching/Filtering on All Columns in KendoUI Grid using DropdownlistFor

I am trying to Filter/Search kendoUI grid using my custom Dropdownlist. I have been able to get a result on singe column filtering but if i try to add new dropdownlist for filtering the Grid i can't get the required result.
my problem is with logic operator and it's different values.
is it the correct way ? or any other suggestions?
I add here the images for more description and hope you to help me please. thanks
HTML dropdowns :
<html>
<div class="form-group col-md-2" style="margin-bottom:0px;">
#Html.Label("Media", htmlAttributes: (new { #class = "col-sm-4 control-label" }))
<div class="col-sm-8" style="float:none;">
#Html.DropDownListFor(model => model.MediaTypeID, (ViewData["media"] as SelectList), "select media", new { #class = "form-control btnregister chosen-select", onchange = "changes_dropdown(this.id)", data_placeholder = "select media", style = "border-bottom:none;border-radius:0px;" })
#* #Html.ValidationMessageFor(model => model.MediaTypeID, "", new { #class = "text-danger" })*#
</div>
</div>
<div class="form-group col-md-2" style="margin-bottom:0px;">
#Html.Label("Outlet", htmlAttributes: (new { #class = "col-sm-4 control-label" }))
<div class="col-sm-8" style="float:none;">
#Html.DropDownListFor(model => model.channel, (ViewData["company"] as SelectList), "select channel", new { #class = "form-control btnregister chosen-select", onchange = "changes_dropdown(this.id)", data_placeholder = "select channel", style = "border-bottom:none;border-radius:0px;" })
#Html.ValidationMessageFor(model => model.channel, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group col-md-2" style="margin-bottom:0px;">
#Html.Label("Start Date", htmlAttributes: (new { #class = "col-sm-6 control-label" }))
<div class="col-sm-6" style="float:none;">
#Html.DropDownListFor(model => model.EntryDate, (ViewData["entryDate"] as SelectList), "select date", new { #class = "form-control btnregister chosen-select", onchange = "changes_dropdown(this.id)", data_placeholder = "select date", style = "border-bottom:none;border-radius:0px;", id = "startDate" })
#Html.ValidationMessageFor(model => model.EntryDate, "", new { #class = "text-danger" })
</div>
</div>
</html>
Javascript Function and filltering:
<script type="text/javascript">
function changes_dropdown(fieldID)
{
var fieldValue = document.getElementById(fieldID).value;
$("#grid").data("kendoGrid").dataSource.filter({
logic: "and",
filters: [
{
field: fieldID,
operator: "contains",
value: fieldValue
}
]
});
}
</script>
At first you don't need to pass id of current field to changes_dropdown function. Instead you can use onchange = "changes_dropdown() and inside this function use var fieldValue = this.value
Also when you define single filter you don't need to specify logic between predicates (http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-filter):
$("#grid").data("kendoGrid").dataSource.filter({
filters: [
{
field: fieldID,
operator: "contains",
value: fieldValue
}
]
});

Resources