How much JavaScript code should be used in asp MVC? [closed] - c#

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am new to the asp MVC programming. Since you can use jQuery/JavaScript code in the View, it seems to me you even can rarely put c# code in the Model/controller. This means most of the business logic is done by jQuery only, and this makes the website looks like a pure JavaScript coded project. If this is true, what's the deal to use C# to code in MVC framework?
If you think c# is easy to be maintained and developed, then how much code should be developed in c# compared with JavaScript in MVC framework? And in what situations should we use c# code in Model/controller rather than JavaScript in View?
Besides, what's the advantages of using asp MVC to develop websites compare with pure jQuery/jQuery QI developed websites?

jQuery/JavaScript in the view will run client-side and will not have access to server-side resources (unless it uses AJAX to retrieve those). C# code is server-side code. One is not a substitute for the other - instead they're complementary to each other.
Business logic in client-side may not be prudent (depends on your application and requirements) because:
you may not want to expose your business logic to clientside as it can be viewed.
it may create significant security gap if exposed.
malicious client can manipulate clientside code and cause code to run with a different logic (some pricing attacks were done in that way in the past).
and a few other reasons.

JavaScript is fast. That's the simple way of answering the advantages to that.
You shouldn't really put any C# code in the views, besides accessing the model and looping through to display results.
When you can, your business logic should work things out, and store them in view models.
Whatever is built in MVC really can be built in JavaScript. C# can give you access to some great libraries such as NewtonJson and LINQ (my favourite).
I use the C# primarily for accessing the database for which we use Entity Framework and performing what calculations where the results can be loaded in a view model.
MVC can quickly offer you ways to add authorisation to different areas of your website, roles etc.

Related

Is it a good way to call web api in asp.net mvc controller? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
We have web application in asp.net mvc using razor code. Now along with web app we need android app. So whatever operations done in mvc controller need to shift in web API controller. So is there any way to convert mvc controller to web API controller? and is it a good approach to call web API in mvc controller?
This is a very common scenario these days.
To answer your question, no you cannot simply convert an MVC controller to WebApi. For one the API is stateless so you need to take that into consideration.
My suggestion is to create a separate WebApi2 project and create the controllers you need there. There may not even be a 1 to 1 correlation to your MVC controllers.
Think of this web api project as your data layer, in a way. It will simply provide the data you need, maybe create some new things and that's it. If you need to save / load data from a database then that's where you do it so both the UI and mobile app use the same data store basically.
Start small, create one controller first with one method in it and then have your MVC app call it and use the data. When you deploy somewhere you will deploy two things :
The UI app
The WebApi project
This means you will need to keep the URL of the WebApi project somewhere so your UI knows about it.
Once you achieve this separation move to your mobile app and call the same WebApi method you've just implemented for the UI project. This will be your Proof of Concept basically.
An Api comes with its own set of rules and challenges, for example :
which methodology are you going to use? REST or not.
How are you going to secure it?
I suggest looking into OAuth2 with JWT for security and if you are interested I can provide some links.
Here is the blog of Taiseer Joudeh, who does a lot of stuff on OAuth2, you'll find loads of articles on the subject there : http://bitoftech.net/taiseer-joudeh-blog/
Here is an article I wrote on OAuth2 and JWT which will take you through a lot of different things :
https://eidand.com/2015/03/28/authorization-system-with-owin-web-api-json-web-tokens/
I always see a controller as a hatch. My controllers never has any business logic. Any logic comes to seperate libraries, which can easily include an API.
be sure the make use of the await keywords for async methods when using API's.
So just replacing your controller logic to an api should work, If you not using many function from the base class which you inherit from webcontroller.

Razor framework - backend or frontend?

What kind of framework is Razor? Is it backend or frontend?
What is the difference between the two types of frameworks?
I'm trying to learn a little bit more about backend and frontend frameworks and since I usually work with Visual Studio Asp.net MVC was wondering about it.
It is not a framework . I think you're misinterpreting certain concepts. Razor is a server side view engine, and it uses C # or VB.NET to generate dynamic content.
Razor Syntax Quick Reference
This question is a couple of years old, but I'm going to add my two cents.
People struggle to give an answer to this question because the terms 'front-end' and 'back-end' aren't formally defined anywhere. Because of that, any answer is purely subjective.
That being said, it is my opinion that the relationship between front-end/back-end and client-side/server-side isn't necessarily one-to-one
I think it helps to think of it like this: client-side and server-side are run-times, while front-end and back-end are a separation of concerns.
'Client-side' always refers to code executing on the client's machine and 'server-side' always refers to code executing on the server. A 'front-end' developer deals with displaying data to the user and getting data from the user, while a back-end developer deals with storing, manipulating, and retrieving that data.
Consider a front-end developer who is tasked with building a UI. Much of the code they write will be the typical HTML / CSS / JS. However, they will also have to deal with the data that is passed to the front-end from the backend. This is where Razor comes into play. The front-end developer will write the Razor code (which executes on the server-side) to display the data.
That is, the front-end developer will write server-side code to help generate the UI, in addition to writing the client-side code that really defines the UI.
Now, I can't imagine a scenario where a back-end developer will write client-side code.
So, to answer your question, Razor is a front-end technology that executes on the server-side runtime. It's only purpose is to generate the UI, which is the concern of the front-end.
Razor is for writing dynamic html page which is front end and c# is for writing backend logic. Although you could move all the backend logic inside razor but its highly not recommended.
Razor allows you on the back-end more easily create views (.cshtml in C#).
It is more like templating system...
http://www.asp.net/web-pages/overview/getting-started/introducing-razor-syntax-c

generate statistic dashboard on asp.net framework [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
i got a project where i must create à web application based on ASP.NET (C#), i need to generate dynamic statistic into a dashboard, the data is extracted from the database. the user can export to XML or CSV file. My database is on SQLserver express 2014 and i m using visual studio 2013.
Looking for advice, what sort of technology to study .
thanks.
Dali, you haven't mentioned if you need to use MVC or WebPages for your project so I will assume it's MVC. However, you can apply the same steps to WebPages with slight modifications.
There are MANY ways to build a dashboard in ASP.Net. Each has its own pros and cons. Please, use your own judgement. This list is nowhere near complete so I would recommend to search possible options online.
1. SSRS Dashboard
Many developers think it's an outdated technology, and, while I agree with them, I still think it's worth to learn if you're trying to implement Reports repository with basic functionality (daily snapshots, parameter filtering, report scheduling). SSRS supports different formats like Excel, HTML, XML, PDF. It's easy to learn and very intuitive. It uses Visual Basic for scripting, and can be easily integrated in .ASPX web pages.
Take a look at some examples.
2. R + MVC
This is a good option for the statistical dashboard. I personally have no experience using R so I cannot tell for sure if it's a viable option in your case. However, it's something to consider when you do your research. Here is a good example to get an idea.
3. JavaScript Chart Library + MVC
Here is good a example. For the JavaScript library, you can use either D3 or HighCharts. Both are great and powerful. Both can be easily integrated with .Net framework. Also, this option is recommended if you already know the JavaScript. There is no need to learn anything else.
4. AnjularJS (or any other JS framework) + MVC (or RESTful API)
This one is my favorite because it provides a lot of room for customization and is flexible enough to satisfy your client needs. Some developers avoid using MVC and replace it with WebAPI (or even SignalR). This also a great solution and allows you to reuse the code if you decide to build a public API based on your dashboard data in real time. Here is what I'm talking about.
P.S. In all these options, SQL Server is used as a main data storage that is why I decided not to include it everywhere. Since you are a .Net developer, it's an obvious choice that you stick with SQL Server, in my opinion.

Front End Dev in Asp.NET MVC? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
So I just started working in a new environment. Its a Microsoft Shop that uses ASP.NET MVC 4 on most of their projects. I'm coming from a mac/linux/open source environment where I worked on the front-end exclusively.
I'm having a hard time working in this .Net environment for a few reasons, one being that ASP.NET MVC is completely new to me. I also feel like to effectively fix issues I need to have some full stack skills too.
I've looked around for some ASP.NET MVC books but most of them expect you to know a bit of C#. I have no interest in learning C# though. What can I do to help myself work more effectively in this environment?
Firstly, Your best resources are the people around you. They understand not just the framework but they way the business is using it. In any framework there is a myriad of ways to do something, it may not be the best way, but its they way they have chosen.
Books are great if you want to get a general understanding before you start, but once you are in there the fastest way to get into it is use the people around you. As questions, lots of questions, make sure they know you aren't incompetent, just that you want to learn.
Secondly, if you don't want to learn C# your in for some trouble, ASP.NET (even doing front end only) will require knowledge of C#. the pages are .cshtml for a reason because they amalgamate C# and HTML in one.
Depending on how deep you are required to go, you may need to write up some controller functionality, meaning you will need to understand C# fully. If you are solely doing .cshtml pages then a limited subset of C# should suffice. However the more you know the easier you will find it in the long run.
C# is one of the language which you can use to drive ASP.Net MVC Technology. You can opt for other languages like VB.Net also. In my answer, I am going to say some options other than C#, that is build your server with JavaScript, render you page with JavaScript framework.
To learn ASP.Net MVC - Pro ASP.Net MVC 4, ASP.Net MVC 4 in Action
If you do not want to learn C#, then you can build applications only with HTML, CSS and JQuery. So the complete middle tier would be of JavaScript. There are JavaScript Servers like Node.js. You can learn Node.js from this book - Node.js in Action.
Instead of using Razor to render pages in ASP.Net MVC, you can use plain HTML and CSS and using JQuery frameworks like KnockOutJs, AngularJs etc. Before you get on to this JavaScript frameworks, its better you refresh/learn your knowledge in JQuery thorugh JQuery in Action.
Having your frontend and middle tier both in JavaScript, removes the complete dependency of ASP.Net MVC and C#. At the same time, even if you Middle Tier (Server) is built with IIS and ASP.Net MVC combination, you can still use JavaScript frameworks to render frontend.
As mentioned above if you want to get started with Middle tier in ASP.Net + IIS combination, C# must be learned (definitely it will not demand in-depth knowledge, but you should get some experiences in concepts like LINQ etc.,). To learn C#, get this book - C# 4.0 Unleashed.
As you just got started, you can go with ASP.Net MVC + C# combination, and then slowly look into other options as I mentioned above.

Which technology should I use to develop a high performance web application [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I have couple of ideas in my brain which I would like to bring out before it's too late. Basically I want to develop a web application which I could sell it to clients. So which technology shall I use to accomplish this? I have been a C and C++ software developer but it's been a very long time since I have developed one. So the things I would like to know is:
Scalability and Performance?
Easy way to develop web application in a faster manner?
Any Framework?
Application server?
and which programming language?
Usually the programming language doesn't really matter. All have their own strengths and weaknesses. All come up with their own best-practices and frameworks.
It's really up to you what's your preference. If you are coming from Microsoft C/C++ I'd use .NET, if you are from Linux world I'd use Java.
Back in the 90s Java was well known as a slow framework, however there was much of myth and the framework architecture is dramatically changed since that. Today, there is no generally slow or fast framework.
You can find thousands of sites in the web that tell you that the one or the other is faster. However, at the end of the day it depends on how you implemented your solution and how you utilized the best features of the framework.
Greets
Flo
I would suggest using C++ with CPPCMS as it's becoming stable and is precisely targeted at high performance web applications.
See if the rationale match your goals.
Build with:
C#, you'll love it (I'm also an old C++ developer)
ASP.Net MVC (Validation, caching, Spark view engine)
Any ORM having a cache layer (I prefer nhibernate)
Database with lots of allocated memory
I kinda think this is almost more like a religious problem, than a real technical issue. For almost every programming language you can find a big website that's using it.
.NET -> Microsoft
Ruby -> Twitter (yes, they have a few issues, but still)
PHP -> Facebook
Java -> Lots of finance companies
Don't know about Phyton, but I'm sure there is.
More important is a good scalable architecture. That is where Twitter kinda screwed it up it seems.
Personally I use ASP.NET. Works fine, is somewhat easy and has a nice IDE. And the market is not so fragmented. Before I used Java with Websphere. Was running on a Sergenti Sun Box, so could definitely handle a lot.
I would more see into what you can get yourself into the quickest. If you know C++ C# or Java are easy to learn.
You should take a look at ASP.NET.
Using ASP.NET has got a lot of advantages, and it is very performant. Here you've got a short list of some advantages:
ASP.NET drastically reduces the amount of code required to build large applications.
With built-in Windows authentication and per-application
configuration, your applications are
safe and secured.
It provides better performance by taking advantage of early binding,
just-in-time compilation, native
optimization, and caching services
right out of the box.
The ASP.NET framework is complemented by a rich toolbox and
designer in the Visual Studio
integrated development environment.
WYSIWYG editing, drag-and-drop server
controls, and automatic deployment are
just a few of the features this
powerful tool provides.
Provides simplicity as ASP.NET makes it easy to perform common tasks,
from simple form submission and client
authentication to deployment and site
configuration.
The source code and HTML are together therefore ASP.NET pages are
easy to maintain and write. Also the
source code is executed on the server.
This provides a lot of power and
flexibility to the web pages.
All the processes are closely monitored and managed by the ASP.NET
runtime, so that if process is dead, a
new process can be created in its
place, which helps keep your
application constantly available to
handle requests.
It is purely server-side technology so, ASP.NET code executes on the
server before it is sent to the
browser.
Being language-independent, it allows you to choose the language that
best applies to your application or
partition your application across many
languages.
ASP.NET makes for easy deployment. There is no need to register
components because the configuration
information is built-in.

Categories

Resources