Skip to main content

My Asp.net mvc,Asp.net, linq and jquery Faqs

Here I want to make the list of every thing about Asp.mvc, linq and jquery I have been involved in or I can get my hands on or find very interesting. The list will keep on growing over time.

How to get the current Route Id in the view from Url?

<%=Url.RequestContext.RouteData.Values["id"] %> 

What is difference between Html.Partial and Html.RenderPartial?

Good complete answer here.

What is Mvc Futures Library?

Please refer here for the answer.
http://stackoverflow.com/questions/2734316/asp-net-mvc-futures-refresh-for-mvc2.

What is TempData?

Answer here

What is Difference between ViewData and ViewBag?

See here And here

Many to Many Relationship in linq to sql ?

http://geekswithblogs.net/WinAZ/archive/2010/01/09/simplified-many-to-many-relationships-with-linq-to-sql.aspx
http://www.codeproject.com/KB/linq/linq-to-sql-many-to-many.aspx
http://www.iaingalloway.com/many-to-many-relationships-in-linq-to-sql-part-2

How to catch error in Jquery's load ?
To Invoke It: Call throw new Exception() from controller's catch
 
var ph = $("#Cat");
            ph.load("/Categories/Index", function (responseText, textStatus, req) {
                if (textStatus == "error") {
                    window.location = "../User/Logon";
                }
                else {
                alert(textstatus);
                }
            });

 
How to Create comma seperated string using linq?
 var Tags = _db.TagPosts.Where(m => m.bint_PostId == id);
 return string.Join(",", (from p in Tags select p.Tag.vcr_TagName)); 

Linq to sql case insensitive string matching?

if (string.Equals(string1,string2,StringComparison.OrdinalIgnoreCase)) 
{ 
}


Exporting Gridview DataSet to Excel


http://stackoverflow.com/questions/5621577/export-from-sql-server-to-excel-file-using-asp-net-and-vb-net

Get the text and value of the selected item of dropdown in jquery
alert($("#selectlist option:selected").text());
alert($("#selectlist option:selected").val());

Find out If a particular element exists in jquery
if ($("#row-" + exist).length) {

  }

Comments

Popular posts from this blog

Asp.net mvc razor render partial view using ajax helper

This is the extension to my blog in which I demonstrated rendering of the partial view using jquery Ajax . I want to demonstrate here yet another way by which partial view can be rendered without page refresh. Here is the implementation. Step 1: I will again be using DisplayData class in my demo. Here is it. public class DisplayData { public int ID { get; set; } public DisplayData(int ID) { this.ID = ID; } } Step 2: Create a PartialDemo page @model IEnumerable<MvcApplication5.Models.DisplayData> @{ ViewBag.Title = "PartialDemo"; } @Ajax.ActionLink("Click 1", "PartialDemo", "PartialDemo", new {Data= "1" }, new AjaxOptions { UpdateTargetId = "rsvpmsg" }) @Ajax.ActionLink("Click 2", "PartialDemo", "PartialDemo", new {Data= "2" }, new AjaxOptions { UpdateTargetId = "rsvpmsg" }) <div id="rsvpms

Asp.net mvc razor render partial view using jquery Ajax

I will going to demonstrate how we can render PartialViews using Jquery Ajax. I will be clicking an a href link ,then I will be calling the controller through jquery Ajax which will fill the partialview for a really nice user experience. Step 1: First of all we will be creating an DisplayData class for the use for this example in the model. public class DisplayData { public int ID { get; set; } public DisplayData(int ID) { this.ID = ID; } } Step 2: We will create a Clicks page and write the following code on it. Specially note empty here which will going to empty and then fill partialview with new records. $(document).ready(function () { $('.msg').click(function () { var id = this.id; $.ajax({ url: "/Category/Display", data: { data: id }, success: function (mydata) { $("#link").empty().appe

Asp.net mvc DataAnnotation ValidateAttribute two properties comparison.

Using Datannotion is great but there are scenarious in which the current attributes compare, range etc becomes inadequate especially for the comparisions. So we create here our own custom validation using ValidationAttribute class which is the base class for all the annotation attributes. So by deriving from it and overriding the Isvalid method we can create our custom attribute for the model. So here is the scenario in which I will be validating the Username against the password which should not be equal. Compare attribute cannot be used in this scenario so I have created a custom attribute for that. Here is the model with the attribute. User View Model [CompareUserPass("UserName", "Password", ErrorMessage = "UserName and password cannot be equal")] public class UserView { [Required(ErrorMessage = "UserName Required")] public string UserName { get; set; } [Required(