- ASP.NET Web API
- Enhancements to default project Templates
- Mobile Project Template
- Display Modes
- JQuery Mobile
- View Switcher
- Browser Overriding
- Task Support For Asynchronous controller
- Empty Project template
Saturday, August 24, 2013
What are the new features introduced in MVC4
FIND() selector in Jquery
To make partial views to preserve the values while doing the http post we need to pass the top level model(parent view model) to partial view.
find() lets you filter on a set of elements based on a selection you've already made. For example if you wanted to set the back-ground color to all the spans inside a div, you could write:
$('#testDiv').find('span').css('background-color', 'red');
We can do the same by using below syntax
$('#testDiv span').css('background-color', 'red');
Here “testDiv” is a div tag.
Find selector is a much faster comparative to above one.
Identifying the elements by attribute values in Jquery
$(‘element[attribute=”value”]’): Selects all elements that have the specified attribute with a value exactly equal to a specified value.
Ex: $('span[id="spnTest1"]').css('background-color', 'red');
$(‘element[attribute^=”value”]’): Selects all elements that have the specified attribute with a value beginning with specified value. The comparison is case sensitive.
Ex: $('span[id^="span"]').css('background-color', 'blue');
$(‘element[attribute$=”value”]’): Selects all elements that have the specified attribute with a value ending with specified value. The comparison is case sensitive.
Ex: $('span[id$="test3"]').css('background-color', 'yellow');
$(‘element[attribute*=”value”]’): Selects all elements that have the specified attribute contains sub string of specified value. The comparison is case sensitive.
EX: $('span[id*="test"]').css('background-color', 'green');
Ex: $('span[id="spnTest1"]').css('background-color', 'red');
$(‘element[attribute^=”value”]’): Selects all elements that have the specified attribute with a value beginning with specified value. The comparison is case sensitive.
Ex: $('span[id^="span"]').css('background-color', 'blue');
$(‘element[attribute$=”value”]’): Selects all elements that have the specified attribute with a value ending with specified value. The comparison is case sensitive.
Ex: $('span[id$="test3"]').css('background-color', 'yellow');
$(‘element[attribute*=”value”]’): Selects all elements that have the specified attribute contains sub string of specified value. The comparison is case sensitive.
EX: $('span[id*="test"]').css('background-color', 'green');
Basic selectors in Jquery
• Identifying the element by tag name
Ex: $('p') -> selects all paragraphs in the document
• Identifying the element by ID
Ex: $(‘#divUser’) -> selects a DOM element which contains ID as “divUser”.
• Identifying the element by class
Ex: $(‘.divUser’) -> selects a DOM element which contains class as “divUser”.
Ex: $('p') -> selects all paragraphs in the document
• Identifying the element by ID
Ex: $(‘#divUser’) -> selects a DOM element which contains ID as “divUser”.
• Identifying the element by class
Ex: $(‘.divUser’) -> selects a DOM element which contains class as “divUser”.
Why to go with Editor Templates instead of partial views in MVC?
The problem with partials is that they do not preserve the navigational context. This means that any input fields that you might have put inside this partial will have incorrect names and the default model binder will not be able to retrieve the values back when you POST.
To make partial views to preserve the values while doing the http post we need to pass the top level model(parent view model) to partial view.
To make partial views to preserve the values while doing the http post we need to pass the top level model(parent view model) to partial view.
Parse the Sql query with out executing it.
declare @sql nvarchar(max)
set @sql = 'select * FROM Students'
declare @testsql nvarchar(max)
declare @result int =1
set @testsql = N'set parseonly on; ' + @sql
BEGIN TRY
exec @result = sp_executesql @testsql
END TRY
BEGIN CATCH
PRINT 'ERROR’
END CATCH
Select @result
-- If it worked, execute it
if @result = 0
begin
exec sp_executesql @sql
end
set @sql = 'select * FROM Students'
declare @testsql nvarchar(max)
declare @result int =1
set @testsql = N'set parseonly on; ' + @sql
BEGIN TRY
exec @result = sp_executesql @testsql
END TRY
BEGIN CATCH
PRINT 'ERROR’
END CATCH
Select @result
-- If it worked, execute it
if @result = 0
begin
exec sp_executesql @sql
end
Adding a custom Jquery function to check whether a element exists in a html page or not using Jquery
Please add the below code your custom .JS file
(function($) {
if (!$.exist) {
$.extend({
exist: function(elm) {
if (typeof elm == null) return false;
if (typeof elm != "object") elm = $(elm);
return elm.length ? true : false;
}
});
$.fn.extend({
exist: function() {
return $.exist($(this));
}
});
}
})(jQuery);
Usage
------------
// With ID
$.exist("#eleID");
// OR
$("#eleID").exist();
// With class name
$.exist(".class-name");
// OR
$(".class-name").exist();
// With just a tag // Probably not best idea as there will be other tags on the site
$.exist("div");
// OR
$("div").exist();
(function($) {
if (!$.exist) {
$.extend({
exist: function(elm) {
if (typeof elm == null) return false;
if (typeof elm != "object") elm = $(elm);
return elm.length ? true : false;
}
});
$.fn.extend({
exist: function() {
return $.exist($(this));
}
});
}
})(jQuery);
Usage
------------
// With ID
$.exist("#eleID");
// OR
$("#eleID").exist();
// With class name
$.exist(".class-name");
// OR
$(".class-name").exist();
// With just a tag // Probably not best idea as there will be other tags on the site
$.exist("div");
// OR
$("div").exist();
Subscribe to:
Comments (Atom)