Monday, February 1, 2016

Enable or disable viewstate in asp.net

View State is the method to preserve the Value of the Page and Controls between round trips. It is a Page-Level State Management technique. View State is turned on by default and normally serializes the data in every control on the page regardless of whether it is actually used  during a post-back.  

These are the main features of view state:
  1. Retains the value of the Control after post-back without using a session.
  2. Stores the value of Pages and Control Properties defined in the page.
  3. Creates a custom View State Provider that lets you store View State Information in a SQL Server Database or in another data store

Maintaining the ViewState is the default setting for ASP.NET Web Forms. 

If you want to NOT maintain the ViewState, include the directive <%@ Page EnableViewState="false" %> at the top of an .aspx page or add the attribute EnableViewState="false" to any control.

Sunday, January 31, 2016

what does int? id means in passing parameter in method?

It means that your parameter could have either integer value of null value. On your method you could use hasValue method to see if the parameter is null or has a valid integer value.

Monday, March 23, 2015

CSS not loading in delployment in server

This is very common issue that when we deploy mvc4 application to server and found that css not loaded and style sheet link looks like
<link href="/Content/themes/base/css?v=myqT7npwmF2ABsuSaHqt8SCvK8UFWpRv7T4M8r3kiK01" rel="stylesheet"/>
solution for this issue is very simple
<compilation debug="false" targetFramework="4.0">

Wednesday, November 5, 2014

How to remove shared layout in MVC

As we know sometimes views has taken shared layout and we don't want to append that in design as we have another design pattern in some cases.

So we have to disable shared layout as it takes by default.


@{
    Layout = null;
}


Thanks

Monday, September 8, 2014

LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)' method, and this method cannot be translated into a store expression.

The Linq query is ultimately transformed into an SQL query and LINQ doesn't know what to do with Session["UserName"] (that gets the "UserName" item).

A common way to workaround this is just to use a local variable to which you'll assign Session["UserName"] and that you'll use in your Linq query...

like  

string loggedUserName = Session["LogedUsername"].ToString();
  var userdetail =
dc.faculties.Where(a => a.F_UserName.Equals(loggedUserName)).FirstOrDefault();

Unable to load the specified metadata resource

MetadataException: Unable to load the specified metadata resource

This means that the application is unable to load the EDMX.

There are several things which can cause this, but most likely, due to invalid connection string. 


Possible Solutions:

1.Check connection string 
2.Refresh model.edmx
3.Select option "Update Model from database"  in model.edmx

Tuesday, September 24, 2013

How To Delete table row in sql database by LINQ query?


First of all get the row form id 

This is a method for delete row from summary table.

So here I pass id for which I want to delete the row

This is database context 

private UserContext database = new UserContext("UserConnection");


table name :summeries

   public ActionResult del_summary(int id = 0)
        {
            var summary_delete = database.summeries.Find(id);

            var delete = database.summeries.Remove(summary_delete);

            database.SaveChanges();

            return RedirectToAction("ExceptionListing");

        }


It will delete row from table.

Thanks for visiting.Please comment here if you have any query regarding it.