Use Selectors in jQuery
The selectors are very useful and would be required at every step while using jQuery. They get the exact element that you want from your HTML document.
- $('*'): This selector selects all elements in the document.
- $("p > *"): This selector selects all elements that are children of a paragraph element.
- $("#specialID"): This selector function gets the element with id="specialID".
- $(".specialClass"): This selector gets all the elements that have the class of specialClass.
- $("li:not(.myclass)"): Selects all elements matched by
- that do not have class="myclass".
- $("a#specialID.specialClass"): This selector matches links with an id of specialID and a class of specialClass.
- $("p a.specialClass"): This selector matches links with a class of specialClass declared within elements.
- $("ul li:first"): This selector gets only the first
- element of the
- .
- $("#container p"): Selects all elements matched by that are descendants of an element that has an id of container.
- $("li > ul"): Selects all elements matched by
- that are children of an element matched by
- $("strong + em"): Selects all elements matched by that immediately follow a sibling element matched by .
- $("p ~ ul"): Selects all elements matched by
- that follow a sibling element matched by .
- $("code, em, strong"): Selects all elements matched by
or or .
- $("p strong, .myclass"): Selects all elements matched by that are descendants of an element matched by as well as all elements that have a class of myclass.
- $(":empty"): Selects all elements that have no children.
- $("p:empty"): Selects all elements matched by that have no children.
- $("div[p]"): Selects all elements matched by that contain an element matched by .
- $("p[.myclass]"): Selects all elements matched by that contain an element with a class of myclass.
- $("a[@rel]"): Selects all elements matched by that have a rel attribute.
- $("input[@name=myname]"): Selects all elements matched by that have a name value exactly equal to myname.
- $("input[@name^=myname]"): Selects all elements matched by that have a name value beginning with myname.
- $("a[@rel$=self]"): Selects all elements matched by that have a class value ending with bar
- $("a[@href*=domain.com]"): Selects all elements matched by that have an href value containing domain.com.
- $("li:even"): Selects all elements matched by
- that have an even index value.
- $("tr:odd"): Selects all elements matched by that have an odd index value.
- $("li:first"): Selects the first
- element.
- $("li:last"): Selects the last
- element.
- $("li:visible"): Selects all elements matched by
- that are visible.
- $("li:hidden"): Selects all elements matched by
- that are hidden.
- $(":radio"): Selects all radio buttons in the form.
- $(":checked"): Selects all checked boxex in the form.
- $(":input"): Selects only form elements (input, select, textarea, button).
- $(":text"): Selects only text elements (input[type=text]).
- $("li:eq(2)"): Selects the third
- element
- $("li:eq(4)"): Selects the fifth
- element
- $("li:lt(2)"): Selects all elements matched by
- element before the third one; in other words, the first two
- elements.
- $("p:lt(3)"): selects all elements matched by elements before the fourth one; in other words the first three elements.
- $("li:gt(1)"): Selects all elements matched by
- after the second one.
- $("p:gt(2)"): Selects all elements matched by after the third one.
- $("div/p"): Selects all elements matched by that are children of an element matched by .
- $("div//code"): Selects all elements matched by
that are descendants of an element matched by
. - $("//p//a"): Selects all elements matched by that are descendants of an element matched by
- $("li:first-child"): Selects all elements matched by
- that are the first child of their parent.
- $("li:last-child"): Selects all elements matched by
- that are the last child of their parent.
- $(":parent"): Selects all elements that are the parent of another element, including text.
- $("li:contains(second)"): Selects all elements matched by
- that contain the text second.
FirstOrDefault Value by Linq
model = from b in db.books.Take(6).ToList()
where b.writerId==id
select b;
var wtrName = model.FirstOrDefault().writer.WriterName;
ViewBag.title = "Book List of Writer : " + wtrName;
where b.writerId==id
select b;
var wtrName = model.FirstOrDefault().writer.WriterName;
ViewBag.title = "Book List of Writer : " + wtrName;
Display All Images from Directory
Model
Method Index
Index Display part
public class ImagesModel
{
public ImagesModel()
{
Images = new List();
}
public List Images { get; set; }
}
Controller{
public ImagesModel()
{
Images = new List
}
public List
}
Method Index
public ActionResult Index()
{
var images = new ImagesModel();
//Read out files from the files directory
var files = Directory.GetFiles(Server.MapPath("~/Content/img"));
//Add them to the model
foreach (var file in files)
images.Images.Add(Path.GetFileName(file));
return View(images);
}
View{
var images = new ImagesModel();
//Read out files from the files directory
var files = Directory.GetFiles(Server.MapPath("~/Content/img"));
//Add them to the model
foreach (var file in files)
images.Images.Add(Path.GetFileName(file));
return View(images);
}
Index Display part
Combo Box, Drop Down List in MVC using Entity Framework
Combo Box, Drop Down List in MVC 4 ASP.NET using Entity Framework>
Models Class
writer.cs
book.cs
Controller
bookController.cs
View
Create.cshtml
Models Class
writer.cs
public class Writer
{
public int WriterId { get; set; }
public string WriterName { get; set; }
}
book.cs
[Bind(Exclude="bookId")]
public class book
{
public int bookId { get; set; }
[Required]
public int writerId { get; set; }
[Required]
public string title { get; set; }
public decimal price { get; set; }
public string imagepath { get; set; }
}
Controller
bookController.cs
public ActionResult Create()
{
ViewBag.WriterId = new SelectList(db.writers, "WriterId", "WriterName");
return View();
}
View
Create.cshtml
@Html.DropDownList("WriterId",string.Empty)
Using Entity Framework
Model
[Bind(Exclude="GenreId")]
public class Genre
{
[ScaffoldColumn(false)]
public int GenreId { get; set; }
public string GenreName { get; set; }
public string Description { get; set; }
public Boolean Status { get; set; }
}
Entity Class
public class MVCBookStoreEntities:DbContext
{
public MVCBookStoreEntities()
: base("name=ApplicationServices")
{ }
public DbSet genres { get; set; }
}
Global.asax
on Application_Start add this
Database.SetInitializer(new DropCreateDatabaseIfModelChanges());
Controller
MVCBookStoreEntities db = new MVCBookStoreEntities();
public ActionResult Index()
{
List gen =new List();
gen=db.genres.ToList();
var model=from g in gen
orderby g.GenreId descending
where g.Status==true
select g;
return View(model);
}
[Bind(Exclude="GenreId")]
public class Genre
{
[ScaffoldColumn(false)]
public int GenreId { get; set; }
public string GenreName { get; set; }
public string Description { get; set; }
public Boolean Status { get; set; }
}
Entity Class
public class MVCBookStoreEntities:DbContext
{
public MVCBookStoreEntities()
: base("name=ApplicationServices")
{ }
public DbSet
}
Global.asax
on Application_Start add this
Database.SetInitializer(new DropCreateDatabaseIfModelChanges
Controller
MVCBookStoreEntities db = new MVCBookStoreEntities();
public ActionResult Index()
{
List
gen=db.genres.ToList();
var model=from g in gen
orderby g.GenreId descending
where g.Status==true
select g;
return View(model);
}
MVC Complete Add/Edit/Delete/Details Controller with Entity FrameWork
public class genreController : Controller
{
//
// GET: /genre/
MVCBookStoreEntities db = new MVCBookStoreEntities();
public ActionResult Index()
{
//var model = db.genres.ToList();
//return View(model);
List gen =new List();
gen=db.genres.ToList();
var model=from g in gen
orderby g.GenreId descending
where g.Status==true
select g;
return View(model);
}
//
// GET: /genre/Details/5
public ActionResult Details(int id)
{
var model = db.genres.Find(id);
return View(model);
}
//
// GET: /genre/Create
public ActionResult Create()
{
return View();
}
//
// POST: /genre/Create
[HttpPost]
public ActionResult Create(Genre addgen)
// public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
//return RedirectToAction("Index");
db.Entry(addgen).State = EntityState.Added;
//db.genres.Add(addgen);
db.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /genre/Edit/5
public ActionResult Edit(int id)
{
var model=db.genres.Find(id);
return View(model);
}
//
// POST: /genre/Edit/5
[HttpPost]
public ActionResult Edit(int id, Genre editgen)
//public ActionResult Edit(int id, FormCollection collection)
{
try
{
if (ModelState.IsValid)
{
// TODO: Add update logic here
editgen.GenreId = id;
db.Entry(editgen).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
else {
return RedirectToAction("Index");
}
}
catch
{
return View();
}
}
//
// GET: /genre/Delete/5
public ActionResult Delete(int id)
{
var model = db.genres.Find(id);
return View(model);
}
//
// POST: /genre/Delete/5
[HttpPost]
public ActionResult Delete(int id, Genre deletegen)
{
try
{
if (ModelState.IsValid)
{
// TODO: Add update logic here
deletegen.GenreId = id;
db.Entry(deletegen).State = EntityState.Deleted;
db.SaveChanges();
return RedirectToAction("Index");
}
else
{
return RedirectToAction("Index");
}
}
catch
{
return View();
}
}
}
{
//
// GET: /genre/
MVCBookStoreEntities db = new MVCBookStoreEntities();
public ActionResult Index()
{
//var model = db.genres.ToList();
//return View(model);
List
gen=db.genres.ToList();
var model=from g in gen
orderby g.GenreId descending
where g.Status==true
select g;
return View(model);
}
//
// GET: /genre/Details/5
public ActionResult Details(int id)
{
var model = db.genres.Find(id);
return View(model);
}
//
// GET: /genre/Create
public ActionResult Create()
{
return View();
}
//
// POST: /genre/Create
[HttpPost]
public ActionResult Create(Genre addgen)
// public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
//return RedirectToAction("Index");
db.Entry(addgen).State = EntityState.Added;
//db.genres.Add(addgen);
db.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /genre/Edit/5
public ActionResult Edit(int id)
{
var model=db.genres.Find(id);
return View(model);
}
//
// POST: /genre/Edit/5
[HttpPost]
public ActionResult Edit(int id, Genre editgen)
//public ActionResult Edit(int id, FormCollection collection)
{
try
{
if (ModelState.IsValid)
{
// TODO: Add update logic here
editgen.GenreId = id;
db.Entry(editgen).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
else {
return RedirectToAction("Index");
}
}
catch
{
return View();
}
}
//
// GET: /genre/Delete/5
public ActionResult Delete(int id)
{
var model = db.genres.Find(id);
return View(model);
}
//
// POST: /genre/Delete/5
[HttpPost]
public ActionResult Delete(int id, Genre deletegen)
{
try
{
if (ModelState.IsValid)
{
// TODO: Add update logic here
deletegen.GenreId = id;
db.Entry(deletegen).State = EntityState.Deleted;
db.SaveChanges();
return RedirectToAction("Index");
}
else
{
return RedirectToAction("Index");
}
}
catch
{
return View();
}
}
}
Installation of EntityFramework 6.0.0-beta1
Microsoft Visual Studio 2012
Tools
Library Package Manager
Package Manager Console
Then
Tools
Library Package Manager
Package Manager Console
Then
PM> Install-Package EntityFramework
-Pre
required Internet Connection............
Scaffold (programming)
Scaffolding is a technique supported by some model-view-controller frameworks, in which the programmer may write a specification that describes how the application database may be used. The compiler uses this specification to generate code that the application can use to create, read, update and delete database entries, effectively treating the template as a "scaffold" on which to build a more powerful application.
Subscribe to:
Posts
(
Atom
)
No comments :
Post a Comment