i noticed some wierd problem i.e i have built a web page on which information comes from database table named "school", when i change some data in that table manually from mssql the web page data is still same as previous, its not gettin' changed, i dn't know how it is possible.
this is my action controller
public ActionResult SchoolDetails(string id,_ASI_School schoolDetails)
{
schoolDetails = SchoolRepository.GetSchoolById(id);
return View(schoolDetails);
}
This is my view
=Html.Encode(Model.SchoolName)
= Html.Encode(Model.SchoolAddress)
= Html.Encode(Model.SchoolEmail)
code for GetSchoolById()..
private static ASIDataContext db = new ASIDataContext();
public static _ASI_School GetSchoolById(string schoolId)
{
return db._ASI_Schools.SingleOrDefault(x => x.SchoolId == schoolId);
}
try putting this above your SchoolDetails ActionResult
[OutputCache( Duration=0)]
MVC does some really nice server side caching as well that clearing the cache on the browser does not fix.
Related
this variable works fine if used by one user, but when used by two or more users then the "static" variable will be read by the next user, the first user instance when filling the gridview there are 5 rows of data and I try to access through other browser when entering the page, gridview on the second user already filled 5 rows of data in input by the first user. then how the solution to this problem? please see my code and give me an solutions. thanks.
static List<ServicesModels> _gridPackageDetail = new List<ServicesModels>();
private void AddListAction(string alfa, string beta)
{
ServicesModels data = new ServicesModels()
{
id_service_detail = Guid.NewGuid(),
scope_name = alfa,
detail_name= beta
};
_gridPackageDetail.Add(data);
}
public ActionResult GridPackageDetail()
{
ViewBag.DataListPackage = _gridPackageDetail.OrderBy(a => a.scope_name).ToList();
return PartialView();
}
my code in mvc3 controller.
The code is working fine, because this is what intended by "static", to have the same data for multi users. In your case you need to create a list or dictionary or multi-dimensional array (any data structure you are comfortABLE with) and save the data per use in it, and then retrieve the data when needed based on the user id.
static List<ServicesModels> _gridPackageDetail = new List<ServicesModels>();
private void AddListAction(string alfa, string beta)
{
ServicesModels data = new ServicesModels()
{
id_service_detail = Guid.NewGuid(),
scope_name = alfa,
detail_name= beta,
user_id = getTheID()// Get the id of the user
};
_gridPackageDetail.Add(data);
}
public ActionResult GridPackageDetail()
{
ViewBag.DataListPackage = _gridPackageDetail.OrderBy(a => a.scope_name && user_id ==getTheID()).ToList();
return PartialView();
}
replace getTheID() by your way of getting the id of the user.
This is used if you want to keep the data of all users. else you should remove the static keyword.
I'm fairly new to mvc, and have started learning asp.net mvc 5 and django
I want to create an application where the user can create a new view at runtime. So lets say I create a feature in the web app for a user to add a new page where they can fill out a form, say the title maybe text, or fields they want to display on the view, and when the user saves it that info gets saved to the db and creates a new view.
My questions are:
can you create dynamic views at runtime?
how do you create the proper url to route to that new page?
if the 1st two are possible can you use a model or viewModel to then display the content from the db for that page?
Any advice on if this can be done would be appreciated. Thanks
I think you need to make a page that saves the user configuration in db as per user demand.
From my end, I suggest the following approach to do it.
Whatever you gets the data from database which are returns like as below snap.
Make one Action in controller and assign those data in one datatable/list in action.
public ActionResult LoadContent()
{
dynamic expando = new ExpandoObject();
var model = expando as IDictionary<string, object>;
/*Let say user insert the detail of employee registration form. Make the
database call and get the distinct detail of particular inserted form by Id
or whatever. As an example below datatable contains the data that you fetch
during database call.*/
DataTable objListResult =
HeaderViewActionHelper.GetFinalResultToRenderInGenericList(id);
if (objListResult != null && objListResult.Rows.Count > 0)
{
foreach (DataRow row in objListResult.Rows)
{
model.Add(row["DisplayName"].ToString(),
row["DisplayNameValue"].ToString());
/*If you want to handle the datatype of each field than you can bifurcation
the type here using If..else or switch..case. For that you need to return
another column in your result from database i.e. DataType coloumn. Add in
your model as, model.Add(row["DisplayName"].ToString(),
row["DisplayNameValue"].ToString(), row["DataType"].ToString());*/
}
}
/* return the model in view. */
return View(model);
}
In the view you can go through the loop over modal and render the detail.
#model dynamic
#using (Html.BeginForm("SubmitActionName", "ControllerName")
{
<div class="table-responsive">
<table>
#if (Model != null)
{
foreach (var row in Model)
{
}
}
</table>
</div>
}
For more detail, Please go through this link.
I'm trying to integrate an OData Web Api with Excel 2013 but I'm facing some troubles
Scenario:
Large database view with ~40 millions rows (MySQL)
Database-first EDMX on top of it (Entity Framework 6.1.0)
EntitySetController.Get() to supply data to the clients (WebApi 2.1)
Excel 2013 to consume OData feed
My server side code had to take into account the huge data that is behind, so I decorated my Get() with [Queryable(PageSize=50)]
public class SerieValuesController : EntitySetController<SerieValue, int>
{
#region DB Property
private EDMWarehouseViewsContainer _DB = null;
public EDMWarehouseViewsContainer DB
{
get
{
if (_DB == null)
_DB = new EDMWarehouseViewsContainer();
return _DB;
}
}
#endregion
[Queryable(PageSize=50)]
public override IQueryable<SerieValue> Get()
{
var options = this.QueryOptions;
IQueryable results = DB.SerieValues;
if (options.Filter != null)
{
results = options.Filter.ApplyTo(results, new ODataQuerySettings());
}
if (options.Top != null)
{
results = options.Top.ApplyTo(results, new ODataQuerySettings());
}
return results as IQueryable<SerieValue>;
}
protected override SerieValue GetEntityByKey(int id)
{
SerieValue entity = DB.SerieValues.Find(id);
return entity;
}
}
If I try to get data in a browser, with these URLs
http://mymachine.lan/odata/SerieValues (this gets correctly the first 50 rows in the view, along with a oData.nextLink node)
http://mymachine.lan/odata/SerieValues?$skip=50 (this get correctly the next 50 rows)
When I try to consume this feed from Excel 2013, it starts downloading the data automatically, page by page, until the memory blows.
So I changed my [Queryable] decoration as this
[Queryable(PageSize=50, MaxSkip=5000)]
After checking in the browser ($skip=4999 works, $skip=5000 works, $skip=5001 gives an error), I tried to download the data in excel again.
Unfortunately Excel stops at 5000 giving a Server Error and no data is displayed.
How can I make it work?
Yes, Excel will ignore paging when achieving data from OData service.
Since you set MaxSkip=5000, it will fail when the excel tries to get the 5001th record. So what is your expected behavior? If you wanna control the amount of return, you can combine $skip and $top in your query, and set MaxSkip and MaxTop in service to control the maximum value.
i'm trying to create an asp.net mvc web application ,some pages need to show the data in "real time" ,this data is on a sql server database ,the data is changing always
i created a stored procedure in sql server , i call this procedure in my controller using Entity framework linq and send the result to the browser using ajax
i used outputcashing to minimize the number of execution of the stored procedure ,
in the same controller there is multiple methode that use the same stored procedure ,every methode execute the same procedure ,
how to emprove the performance of my application ,
is there a way to execute the stored procedure only one time for all the controller ??
this is my controller my objective is to minimize the use of the database
[OutputCache(Duration = 20, VaryByParam = "*")]
public class JobsETLController : Controller
{
private ETL_REP_MAUIEntities db = new ETL_REP_MAUIEntities();
public ObjectResult<BIOGetETLJobs_Result> ETLJobs;
public JobsETLController()
{
ETLJobs =db.BIOGetETLJobs();
}
public ActionResult Indexp()
{
var y = from xx in ETLJobs
where xx.etat!="Completed"
orderby xx.etat ascending
select xx;
return PartialView(y);
}
public ActionResult IndexpAll()
{
var y = from xx in ETLJobs
where xx.etat == "Completed"
select xx;
return PartialView(y);
}
If your server is not in a web farm (multiple servers) then you can cache the data in the Asp.net Cache (this is not output cacheing, it's data cacheing). You simply set a 5 minute time limit on the expiration of the data (you say the data needs to update every 5 minutes) so that when a controller needs the data it first checks the cache, and if it's not there it will then execute the stored procedure.
MyData items;
items = (MyData)Cache["MyData"];
if(items == null)
{
items = DoQueryToReturnItems();
Cache.Add("MyData", items, null, DateTime.Now.AddMinutes(5), ..);
}
It's even possible to setup the cache item to be dependent upon a SqlDependency so that when the data changes, the cache can be updated.
I'm having trouble getting a ModelUpdate or TryModelUpdate to work in my code.
I'm using the default Role Manager and Login system created by MVC when running the ASP.Net configuration tool. What I'm trying to do is add another column to the Users table so I can record if my users are also customers. So I want to record their CustomerID there.
I used the ADO Entity Data Model to generate all my model code based off my database. The code it created for the field I want to update is here:
public string CustomerID
{
get
{
return this._CustomerID;
}
set
{
this.OnCustomerIDChanging(value);
this.ReportPropertyChanging("CustomerID");
this._CustomerID = global::System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value, true);
this.ReportPropertyChanged("CustomerID");
this.OnCustomerIDChanged();
}
}
private string _CustomerID;
partial void OnCustomerIDChanging(string value);
partial void OnCustomerIDChanged();
In my controller Im trying to update the CustomerID field with this code:
var userToUpdate = dbu.aspnet_Users.First(u => u.UserName == User.Identity.Name);
UpdateModel(userToUpdate, new string[] { "CustomerID"}, txtID);
dbu.SaveChanges();
But I get an error saying the overload method has some invalid arguments.
I get that the issue is in assigning txtID to CustomerID based off the error, but whats the correct way to do it?
If I need to add more info please let me know.
I figured it out. Apparantly ModelUpdate won't let me pass in custom data and it needs to be passed in from the Form Collection. So using UpdateModel(userToUpdate, new string[] {"CustomerID"}, form.ToValueProvider()); worked.