Watch this example on YouTube:
Replace
@Html.CheckBoxFor(x => x.MyQuestions)
with
@Html.CheckBox("MyQuestions", Model.MyQuestions ?? false)
Replace
@Html.CheckBoxFor(x => x.MyQuestions)
with
@Html.CheckBox("MyQuestions", Model.MyQuestions ?? false)
1. Validation
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
var rule = new ModelClientValidationRule
{
ValidationType = "validatecheckbox",
ErrorMessage = "Fix it!"
};
rule.ValidationParameters.Add("fields", string.Join(",", _fields));
yield return rule;
}
2. JS
$.validator.addMethod('validatecheckbox', function (value, element, params) {
debugger
var isValid = true;
if ($(params)[0].fields[1].val() == "True"){
if ($(params)[0].fields[0][0].checked == false) {
isValid = false;
}
}
});
Replace
@model WebApplication3.Models.EmployeeList
@using (Html.BeginForm(null, null, FormMethod.Post))
{
if (Model.myEmployees != null)
{
foreach (var item in Model.myEmployees)
{
@Html.CheckBoxFor(modelItem => item.IsValid.Value, new { id = item.EmployeeID})
@Html.DisplayFor(modelItem => item.FirstName)
<br />
}
}
}
with
@model WebApplication3.Models.EmployeeList
@using (Html.BeginForm(null, null, FormMethod.Post))
{
if (Model.myEmployees != null)
{
foreach (var item in Model.myEmployees)
{
@Html.CheckBoxFor(modelItem => item.IsValid.Value, new { id = item.EmployeeID, @disabled = "true"})
@Html.DisplayFor(modelItem => item.FirstName)
<br />
}
}
}
To fix it replace
@model WebApplication3.Models.EmployeeList
@using (Html.BeginForm(null, null, FormMethod.Post))
{
if (Model.myEmployees != null)
{
foreach (var item in Model.myEmployees)
{
@Html.CheckBoxFor(modelItem => item.IsValid.GetValueOrDefault, new { id = item.EmployeeID })
@Html.DisplayFor(modelItem => item.FirstName)
}
}
}
with
@model WebApplication3.Models.EmployeeList
@using (Html.BeginForm(null, null, FormMethod.Post))
{
if (Model.myEmployees != null)
{
foreach (var item in Model.myEmployees)
{
@Html.CheckBoxFor(modelItem => item.IsValid.Value, new { id = item.EmployeeID })
@Html.DisplayFor(modelItem => item.FirstName)
}
}
}
to fix it replace
@model WebApplication3.Models.EmployeeList
@using (Html.BeginForm(null, null, FormMethod.Post))
{
if (Model.myEmployees != null)
{
foreach (var item in Model.myEmployees)
{
@Html.CheckBoxFor(modelItem => item.IsValid, new { id = item.EmployeeID })
@Html.DisplayFor(modelItem => item.FirstName)
}
}
}
with
@model WebApplication3.Models.EmployeeList
@using (Html.BeginForm(null, null, FormMethod.Post))
{
if (Model.myEmployees != null)
{
foreach (var item in Model.myEmployees)
{
@Html.CheckBoxFor(modelItem => item.IsValid.Value, new { id = item.EmployeeID })
@Html.DisplayFor(modelItem => item.FirstName)
}
}
}
To fix this error replace (semicolon) in view
@model WebApplication3.Models.EmployeeList;
with
@model WebApplication3.Models.EmployeeList
Declare @Test varchar(100) = 'aaa@aaa';
IF @Test Like '%@%'
BEGIN
print ' contains @'
END
ELSE
BEGIN
print ' doesn''t contain @'
END
Watch this example on YouTube
ALter Table Test01
Alter Column RealName Varchar(100)
Watch this example on YouTube
exec sp_rename 'TableName.CurrentColumnName', 'NewColumnName', 'COLUMN'
Watch this example on YouTube
exec sp_rename 'CurrentTableName' , 'NewTableName'
Watch this example on YouTube
To fix it replace
Alter Table Test1
Add IsValid bit not null Default 0
with
IF COL_LENGTH('dbo.Test1', 'IsValid') Is Null
Begin
Alter Table Test1
Add IsValid bit not null Default 0
End
Watch this example on YouTube
IF COL_LENGTH('dbo.Test3', 'IsValid') is null
Begin
Alter Table Test3 Add IsValid bit not null default 0
End
Select * from Test3
Watch this example on YouTube
To fix it replace
Alter Table Test1
Add IsValid bit not null
with
Alter Table Test1
Add IsValid bit not null Default 0
Watch this example on YouTube
1. View
@{
ViewBag.Title = "Home Page";
}
<div class="AddPopUp">
@Html.Label("Add pop up")
</div>
<div class="modal fade" id="MyPopUp" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
here are going your controls etc
</div>
</div>
</div>
</div>
@section Scripts{
<script type="text/javascript">
$(document).ready(function () {
$(".AddPopUp").click(function (e) {
$('#MyPopUp').modal('show');
});
});
</script>
}
2. CSS
.modal-content{
height: 500px;
width: 700px;
}
Watch this example on YouTube
1. Model
public interface IExtensionTest
{
void DoSomething();
}
public class ExtensionTest: IExtensionTest
{
public void DoSomething() { }
}
public static class SomethingElse {
public static string ReturnSomething(this IExtensionTest t, string s)
{
return "returning: " + s;
}
}
2. Controller
public ActionResult Index()Watch this example on YouTube
Watch this example on YouTube
TimeSpan startSomething = new TimeSpan(8, 0, 0);
TimeSpan endSomething = new TimeSpan(16, 0, 0);
TimeSpan now = DateTime.Now.TimeOfDay;
if ((now > startSomething) && (now < endSomething))
{
//do something here
}
Watch this example on YouTube
if (System.DateTime.Now.DayOfWeek == DayOfWeek.Friday)
{
// do somehting here
}
Watch this example on YouTube
String t = Convert.ToDateTime(DateTime.Now).ToUniversalTime().ToString("yyyy/MM/dd HH:mm UTC");