|
Sure thing! If you have any question, feel free to ask, me and many other members are willing to help. Google also has an abundance of questions and answers.
Just to give you a little perception on the view:
Your controller will pass in a "model" to the View. The model can be your domain object, or a view model. I don't want to go into too many details and make it more confusing. You will learn these things as you get more into Asp.Net Mvc.
The view is a template with all the html and razor code. A sample template will be like this:
<!--
<h1>@Model.Name</h1>
<img src="@Model.ImageUrl" />
The razor templating engine then parses the HTML, fills in the model properties from the controller, and renders the raw HTML in the browser. Asp.MVC does all that automatically on the backend.
This produces clean and concise HTML, and lets you make it as semantic as you like.
It is all very beautiful.
H.B.
|
|
|
|
|
Cool, I was going to ask if I should use razor.
Installing that VS2013 Community Edition right now, and will start again today.
I've always had regrets about adopting asp.net webforms versions, so much of it was just stupid.
Was considering that Ruby on Rails or just going back to PHP and Linux, but I see a lot of PHP sites that I frequent using MVC now. I think Best Buy is now MVC as well.
|
|
|
|
|
MVC4 is actually quite old now. MVC 5.2.2 is the most recent version, and MVC6 is in development (for release later this year). You can download the free Community Edition of Visual Studio 2013 for personal use to learn MVC 5.x, or you can download the Visual Studio 2015 CTP if you want to get a head start on MVC6.
--
Where are we going? And why am I in this handbasket?
|
|
|
|
|
My action pack or MSDN subscription expired for VS2013, I'll try the community version and give 5 a spin.
I was just working on MVC 4 just now, watching the Code Project Article "learn in 7 days"
So I guess I will dive into this this week, and build my website in it first.
Thanks for the version info, I didn't know about that.
Learn MVC (Model View Controller) step by step in 7 days – Day 1[^]
|
|
|
|
|
Any one have dll and source code for this
to convert .vox file format to mp3 format.
I am working wthi Alvas.Audio but its not working
and its also asking for License.
Plz Help...
|
|
|
|
|
Does this have anything to do with ASP.NET? If not I suggest you try the Alvas.Audio website, and also use properly licenced software.
|
|
|
|
|
Thanks
Richard MacCutchan
|
|
|
|
|
Am having the following code to find the Number of Alphabets and Number of Numeric characters from a string contains alpha numeric characters.
Public Sub CountAlphaNumeric(ByVal input As String)
Dim alphaCount = input.Count(Function(c) Char.IsLetter(c))
Dim numericCount = input.Count(Function(c) Char.IsDigit(c))
MessageBox.Show(String.Format("Number of alphabets : {0}", alphaCount))
MessageBox.Show(String.Format("Number of numerics : {0}", numericCount))
End Sub
Is their any alternate method are available? I think it is the simplest.
sujith karivelil
|
|
|
|
|
That is Linq at work, what is your question?
|
|
|
|
|
He is probably looking for alternate method.
May be, simple for /foreach loop.
Life is a computer program and everyone is the programmer of his own life.
|
|
|
|
|
I need download forum plugin in C# asp.net and how can i add plugin in asp.net
|
|
|
|
|
You should search in tutorial website instead of asking it in forum.
We can't help unless you have a pin point question.
Life is a computer program and everyone is the programmer of his own life.
|
|
|
|
|
What is your question? It is not clear.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I am trying to develop a contact form with a simple html and css but now I have to do the file asp not know how to do and do not know where to start. Can you help me out?
sorry for my bad English
http://jsfiddle.net/yt95fj0q/[^]
|
|
|
|
|
I've outsourced my enterprise level project to a freelancer and I got a quite good setup too. But now that contract has finished and the person has also moved to a new technology, in other words not willing to extend the contract. Now I'm looking into this code on myself. I do have a 2 3 years of background in C# and MVC. Below is a rough idea of my application architecture. Hopefully I've tried my best to abstract the architectural details of an enterprise level application. Please let me know if you need further brief on any of the questions.
All my Entities are defined as C# POCO classes as:
public class Product : BaseEntity
{
public int ProductId { get; set; }
public string ProductName { get; set; }
}
Now I've a IDbContext like as :
public interface IDbContext : IDisposable
{
IDbSet<TEntity> Set<TEntity>() where TEntity : BaseEntity;
}
Base Entity is a Partial POCO class that each POCO entity is inheriting. Here is a class that implements this IDBContext as:
public class MyObjectContext : DbContext, IDbContext
{
public new IDbSet<TEntity> Set<TEntity>() where TEntity : BaseEntity
{
return base.Set<TEntity>();
}
}
Now I've defined a IDbContextFactory that is responsible for providing the DBContexts as :
public interface IDbContextFactory
{
Lazy<IDbContext> CreateDbContext();
}
The class implementing this IDBContextFactory interface is having below structure :
public class MyDbContextFactory : IDbContextFactory
{
public MyDbContextFactory(string dbConnectionString)
{
_dbConnectionString = Settings.DbConnectionString;
_dbContext = CreateDbContext();
}
public IDbContext CreateDbContext()
{
IDbContext dbContext = new IDbContext(() => CreateNewContext());
return dbContext;
}
private MyObjectContext CreateNewContext()
{
return new MyObjectContext (_dbConnectionString);
}
}
Here IRepo Pattern comes into role as:
public partial interface IRepository<T> where T : BaseEntity
{
T GetById(object id);
}
Now the Repository class implementing this Interface is as below :
public partial class EfRepository<T> : IRepository<T> where T : BaseEntity
{
private readonly Lazy<IDbContext> _dbContext;
private readonly IDbContextFactory _dbContextFactory;
private readonly Lazy<ObjectStateManager> _objectStateManager;
public EfRepository(IDbContextFactory dbContextFactory)
{
_dbContextFactory = dbContextFactory;
_dbContext= _dbContextFactory.CreateDbContext();
_objectStateManager= new Lazy<ObjectStateManager>(() => ((IObjectContextAdapter)_dbContext.Value).ObjectContext.ObjectStateManager);
}
public T GetById(object id)
{
return this.Entities.Find(id);
}
}
Till now we are done with the Infrastructure level setup for DB Access Management. Now the thing is to utilize this setup into Controllers(as I'm having directly accessing Repositories from Controllers) to as below :
public CountryController(Lazy<IRepository<Country>> countryRepository)
{
_countryRepository = countryRepository;
}
public Country GetCountryById(int id)
{
Country country = _countryRepository.Value.GetById(id);
if (country != null)
return country;
else
return null;
}
Hopefully all above is clear. Now here are the some questions that I need to be answered :
1) Why we are having this layered flow like as:
IDBContext -> IDBContextFactory -> IRepository <T>
and then finally using this IRepository into Controllers for accessing Data objects. In other words why we are relying on Interfaces instead of actual Class Objects while implementing Constructor Injection for Country Controller ?
2) Is this the correct approach for a Enterprise level Application as it should be much scalable for future purpose. If there is any other then I would be glad to know about that ?
3) In Controller's constructor I've used Lazy>, so what's the purpose of this Lazy and is it beneficial actually If yes then in what way ?
modified 29-Jan-15 7:16am.
|
|
|
|
|
|
Interfaces are used over concrete classes mainly to allow dependency injection and also better unit testing. If your code has neither of these then interfaces might have been used anyway so that if you do use DI or unit testing in the future then you don't have to re-factor all of your code.
|
|
|
|
|
While it's true that interfaces are useful for these purposes, that's not why they exist or why they are mainly used.
Interface Segregation Principle is one of the Five principles of SOLID design, and stands on its own beyond its use in testing or DI. Interfaces are used to decouple implementation from contract and are important in many other patterns and practices.
Do not fall into the trap of thinking they are only useful for testing or DI, and they don't need to be used otherwise.
--
Where are we going? And why am I in this handbasket?
|
|
|
|
|
Yes I know what they are used for thank you very much. I was trying to give a real-world answer to the real-world question that was posted. The question wasn't "Why should I use an interface" so my answer was not addressing interfaces in general. I didn't say they are only used for DI and unit testing and that they don't need to be used elsewhere.
|
|
|
|
|
This is a variation of a fairly common way of abstracting your data layer in Unit of Work and Repository patterns.
First, let me say there is nothing "enterprise" about this. It's used in both small, medium and large applications. So anyone that told you this was about enterprise development was feeding you a line.
Second, this particular implementation is a bit heavy on the abstractions.. and could probably be slimed down, but there is basically nothing wrong with it, other than having to maintain all those extra abstractions. (also, depending on who you talk to, some people feel that generic repositories are a bad idea, and an anti-pattern. I'm one of them, but It is a controversial subject).
Third, if you're using Entity Framework as your underlying data model, these abstractions are probably just extra noise since EF already provides these abstractions in the form of your DbContext and DbSet, which are already Unit of Work and Generic Repsitory respectively. You can add interfaces to these to make them more Dependency Injection friendly fairly easily, and as of EF6 they provide mockability so neither DI or Unit testing are good reasons to add the extra abstraction layers anymore. However, some people like the comfort of knowledge that they may want to replace their data layer some day and adding these abstractions (in theory) makes that easier (although in practice it's usually not so simple as these are leaky abstractions which tend to leak into your application layers anyways).
However, having said all that.. if you already have this infrastructure, I wouldn't go ripping it out unless you find it to be too burdensome to maintain.
Now, on to the interfaces... Yes, you absolutely should be using interfaces. For reasons of Unit testing and Dependency Injection, as well interface segregation principle. Using an interface helps decouple your implementation from the contract you use to access it.
It's important to realize that "enterprise architecture" is a lot more than just adding an abstracted data layer. It's creating standards that your enterprise follows, and architecting your suite of applications to work together. It's having an infrastructure or technologies, like Service Busses, or Message Queues and planning redundancy, durability, and failability. In short, it's about seeing the forest and not the trees.
--
Where are we going? And why am I in this handbasket?
|
|
|
|
|
Hello Good Sirs! I'm new to asp.net environment and I was wondering how can I launch thisexe. from a button. Also, how I can throw the scanned qrcode to a textbox?
Every answer will be much appreciated! Please do reply!
Thank you so much! More power!
|
|
|
|
|
Anyone can guide me?
|
|
|
|
|
Hello;
I'm working on a simple login form in c# in asp.net. I'd like to bind a key to the password and then save it in encrypted form. When the user logs in, he should enter his key and password. The key will be bind to the password and then compared to the one stored on the database.
Please help me with the binding process and encryption.
Thanks.
|
|
|
|
|
|
How is the key any different from the password then? Key + Password = Password... they're the same thing. Just have the user enter both in the password field, and use standard hashing.
--
Where are we going? And why am I in this handbasket?
|
|
|
|