I have a MVC application that I am building with RavenDB as the main database
In my application, I need a calendar control that needs to be strongly data binded (with RavenDB data)I need calendar control to post data to raven, show dates from ravendb on a calendar control (two way data flow) etc..
Any one have any suggestions for me.. probably some one who did this sort of thing using ravendb, mvc and a calendar control.
What calendar control out there best suits my needs here.. a Jquery date picker? Telerik MVC Calendar ? or any other?
Any input, comments, help is appreciated.
Well RavenDB allows you to deserialize into a regular POCO class, so given a class like this:
public class User
{
public string Id { get; set; }
public DateTime date { get; set; }
}
You can then just load a doc like so:
session.Load<User>("users/1");
From that point onwards you can use the object however you want. You can bind against it, pass it into the view, add attributes to it, etc.
Related
I'm using ASP.NET Core MVC 2. I need to operator can change some elements of Models or view codes. How I can code or design for it.
For example: I have a "news" model and I want to operator (final user of website, who can't code or access to visual studio) can add this to "news" model:
public string ImageUrl { get; set; }
and also can change the database without coding.
Thanks
If you want to design a completely extensible model, you could use something called Entity–attribute–value model (EAV).
Your model might have a couple common attributes like Title and Summary. Then you might have a list of Custom Fields, the first of which could be ImageUrl. You could create your own class called CustomField or something similar, which would have properties such as FieldName, and DataType.
public string Title { get; set; }
public string Summary { get; set; }
public List<CustomField> CustomFields { get; set; }
You would then have a table full of custom field values and the tables they belong to. It gets pretty complex.
When you want to automatically reflect your model changes to the database, you will need an ORM framework like EF (Entity Framework). You can check more here.
In order for your case to happen is to build your own configuration platform that may use several tools and mechanincs that will allow you to generate code and then compile it. Such as T4 and more.
In general, this is a very hard task to accomplish and even big experienced teams would have troubles to build something similar.
I can not post any code, as this would only seem a desperate approach.
I'm in the process of refitting a website that I'd previously built using ASP.net with VB in the code-behind, into MVC with VB so that it's more responsive to different screen sizes and device types.
So far I've been able to replicate six of the pages plus the Site.Master files. Now I'm turning my attention to the Contact page which in asp.net takes data from a form, validates it for completion and data-type compliance and then passes it to the code-behind which uses it to generate an email.
I've done quite a lot of reading which suggests using a Model but all the examples I've found then use that Model to populate or query a database using LINQ.
How can I do this without a database?
The M in MVC stands for Model, not Mdatabase. You can use whatever you want as the model. Most applications use a database and most .NET applications use EF to access a database (or at least Microsoft want it that way) but you can use whatever you want.
Using a database engine is recommended as permanent storage, but essentially you can create model class for contact page without involving a database like this:
public class Contact
{
[Required]
public String Name { get; set; }
[Required]
public String EmailAddress { get; set; }
}
And you can use LINQ/lambda expressions after wrapping your model class into a collection (e.g. List), as example:
var list = new List<Contact>();
list.Add(new Contact { ... }); // adding items to the list
// Lambda syntax
var name = list.Select(x => x.Name); // returns a value from the list
// LINQ syntax
var email = (from item in list
select item.EmailAddress);
Then you can convert the code-behind logic to a controller action method as ActionResult each for GET and POST request. Afterwards, Redirect, RedirectToAction or simply return View() after data submission can be used for page handling.
About responsive page design to work with different screen sizes and device types, MVC itself not designed to present responsive layouts by default. You need to alter some HTML & CSS-related attributes, as similar problem here:
How to make an MVC web application adjust to automatically fit different screen sizes
NB: Since your problem doesn't include any code, the provided codes are just examples as figure to what should be done.
I am working on multi-language enabled mvc application. I have a translation table in database, which I bring on application start and save it in application memory.
The database structure is {TextId, LanguageId, Translation}. TextId is assigned to each UI element (like label, validators, dropdown list text, etc.). There is an admin interface to manage the translation text.
I want to know what is a good way to show translated text on UI, and where is the best place to do the actual translation. I do not want to use the resource manager, since the database is being used in other Asp & Asp.Net webforms applications.
Here is the model (for example)
public class UserLoginModel
{
[Required(ErrorMessage="ER001")]
[Range(6,10,ErrorMessage="ER002")]
[Display(Description="TX001", Name="TX002")]
public string LoginId { get; set; }
[Required(ErrorMessage="ER003"), DataType(DataType.Password)]
public string Password { get; set; }
public bool RememberMe { get; set; }
}
Language Id will be in Session["LanguageId"], and TranslationText is in Application variable.
Models reside in separate project, hence there is not direct access to session, but I can use DI (don't know whether it is a good practice!)
Here are following things I was considering:
Write Html helper extension like #Html.TranslateText("TX001"). I started with this method, but soon realized that #Html.ValidationMessage accepts only one message, irrespective of multiple validator attributes on property. I cannot use EditorFor templates either.
Use javascript to replace text ids with appropriate messages
Use reflection on model and replace text ids for attributes.
I am leaning towards option 3, by extending ModelMetadataProvider, or writing action filter attribute, or in EditorForModel template.
I am very confused on how to proceed. I am still in process of learning MVC. Hence. I would like to ask experts on how to handle this problem in best possible way.
Thanks,
After building my application in ASP.NET MVC and MS sql server, I would now like to display some statistics regarding my data.
What would be the easiest way to create HTML reports which are built of data crossing several tables? (Once the fields are picked they'll be static, meanning a single view is required)
I though their ought to be something in the lines of a wizard letting you drag fields from your tables to a form and generates the logic behind...
I wrote a blog post about this in September. It's a way to render a PDF content type using an RPT file in the application. It covers everything except the creation of the RDLC file, including how to write unit tests for the controller.
Microsoft Reporting Services?
"I though their ought to be something in the lines of a wizard letting you drag fields from your tables to a form and generates the logic behind..." - this is the basic idea behind ASP.NET WebForms. But, please do not abandon MVC in favour of WebForms.
One way to achieve what you want is to create a class representing your stats, e.g.
public class Statistic
{
public string TableName { get; set; }
public int RowCount { get; set; }
}
Your Model code could populate an IList<Statistic> instance which is passed to your View, which renders the stats accordingly.
You could take a look at Dynamic Data .... http://www.asp.net/dynamicdata
How do I integrate ReportViewer in asp.net MVC project?
I want to add business objects of MVCProject.Model namespace. ReportViewer allows Business objects of DataSet.
Is it possible to choose other data source, like LinqDataSource, or Direct object to LINQ-to-SQL class objects?
What would be the best solution to add reports in an MVC project?
An alternative way to do this would be to generate the report on the reporting server, then stream it to the mvc app as a PDF.
I got an idea that is not tested but may work.
1- Place report viewer control in a standard ASP.Net web form page (e.g. ReportViewer.aspx)
2- Under your MVC, add an iframe that references to this ReportViewer.aspx page
3- Pass parameters to the page using sessions or query strings
Let me know if th is works
It's gonna be tough. First, you need ViewState so you'll need to host the report in a regular WebForms page. This isn't too bad though - WebForms and MVC work fine side-by-side.
The hard part is binding to real IEnumerable objects and not those phoney-baloney ObjectDataSources.
The first step is to build up a report data model. You can do this in code, with queries, whatever, however you want. A structure something like this (but obviously much bigger) is typical:
public class ReportSource
{
public Floogle[] Floogles { get; set; }
}
public class Floogle
{
public Doodad[] Doodads { get; set; }
public string Text { get; set; }
}
public class Doodad
{
public int Number { get; set; }
}
The trick is to use a BindingSource control in your report and set the DataSource property to typeof(ReportSource) - yes, the data source is the type of your report model.
When designing your report you won't get a lot of richness, but you'll be able to do it.
As far as third party reporting solutions go, we've found Telerik's to be the best option.
I've got a small project I threw up on codeplex that is an mvc project with a report.
http://mvctaskmanagement.codeplex.com/
Basically since I do dev on an XP box, my web form had to get pushed to a separate project. Since I have a service layer proj, I stuck it in there.
From there I call my report via a ajax post shooting the params over to the report page, which then passes it down to the same service layer used to generate the preview.
Good luck!