European ASP.NET MVC Hosting

BLOG about Latest ASP.NET MVC Hosting and Its Technology - Dedicated to European Windows Hosting Customer

European ASP.NET MVC 5 Hosting - UK :: ASP.NET MVC 5 Scaffolding

clock October 13, 2014 07:28 by author Scott

In this article, I will show you how to use Scaffolding With your ASP.net MVC 5 Application. I assume that you all know about scaffolding and I don’t need to explain it again. In our previous post, we have also explained about Scaffolding with the Repository Pattern in ASP.NET MVC 3.

In this article, we will be more focus in adding scaffolded item to ASP.net MVC 5.

1. Let's create an ASP.net MVC 5 web application in Visual Studio 2013 and name it as ScaffoldingMVC5.

2. Right click your Controllers folder and Add New Scaffolded Item is as below.

3. From the Add Scaffold window, select the MVC 5 Controller with views,using Entity Framework scaffold template.

4. Add a controller. Please see the below screenshot

Then, please fill a name for your Data context as below, for example DataContext

5. You have done great job and this is the result

Testing the Result

Index Page

Create Page

Details Page

Edit Page

Delete Page

All above CRUD operations were generated according to our Model class Pet.

Pet.cs

Key points of the above code

  • [ScaffoldColumn(false)] means,the property which it declared will not use for scaffolding.In other words, that property will not be shown on the UI (i.e. Created property will not be shown).
  • Data validations of the form elements are happening ,according to the above model's Data Annotation values.
  • Let's explore it.

If you click the Create button, without entering anything.What will happen ?

What if you try to enter a wrong data type ?

 


Calender has been shown, if it's a DateTime property.

Great, right?



ASP.NET MVC 6 Hosting - HostForLIFE.eu :: Updating Multiple Row Using ASP.NET MVC and Entity Framework

clock October 7, 2014 12:11 by author Peter

In this post we are going to update multiple row using ASP.NET MVC and Entity Framework.  Just follow these steps below:
1. First we need to create a project.
Go to Menu File > New > Project > Select ASP.NET MVC web application > Entry Application Name > Click OK.


2. Add a Database.
Go to Solution Explorer > Right Click on App_Data folder > Add > New item > Select SQL Server Database Under Data > Enter Database name > Add. 
Open Database and add a table for update operation. Here I am creating a table called Contacts.

3. Add Entity Data Model.
Go to Solution Explorer > Right Click on Project Name from Solution Explorer folder > Add > New item > Select ADO.net Entity Data Model under data > Enter model name > Add.
A popup window will come (Entity Data Model Wizard) > Select Generate from database > Next > Chose your data connection > select your database > next > Select tables > enter Model Namespace > Finish.

After Creating Data model, we have to modify our generated entity(table) for Apply validation for required fields.

Here we need to modify contact.cs fileOpen file and modify as for enable validation.
namespace UpdateMultiRecord
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    public partial class Contac
  {
        [Required]        
        public int ContactID { get; set; }
        [Required]
        public string ContactPerson { get; set; }       
 [Required]
        public string Contactno { get; set; }
        public string EmailID { get; set; }
    }
}


Here I am using Home controller index action.

Get Action      
[HttpGet]
        public ActionResult Index()
        {
            List<Contact> model = new List<Contact>();
            using (MyDatabaseEntities dc = new MyDatabaseEntities())
            {
                model = dc.Contacts.ToList();
            }
            return View(model);

        }     
Post Action       
 [HttpPost]
        public ActionResult Index(List<Contact> list)
        {
           if (ModelState.IsValid)
           {
               using (MyDatabaseEntities dc = new MyDatabaseEntities())
                {
                    foreach (var i in list)
                    {

                        var c = dc.Contacts.Where(a =>                                  
                        a.ContactID.Equals(i.ContactID)).FirstOrDefault();
                        if (c != null)
                        {
                            c.ContactPerson = i.ContactPerson;
                            c.Contactno = i.Contactno;
                            c.EmailID = i.EmailID;
                        }
                    }
                    dc.SaveChanges();
                }
                ViewBag.Message = "Successfully Updated.";
                return View(list);
            }
            else
            {
               ViewBag.Message = "Failed ! Please try again.";
                return View(list);
            }
        }       
Create View for Update Multiple Row.
@model List<UpdateMultiRecord.Contact>
@{
    ViewBag.Title = "Update multiple row at once Using MVC 4 and EF ";
}
@using (@Html.BeginForm("Index","Home", FormMethod.Post))
{
    <table>
            <tr>
                <th></th>               
                <th>Contact Person</th>
                <th>Contact No</th>
                <th>Email ID</th>
            </tr>
        @for (int i = 0; i < Model.Count; i++)
        {
            <tr>               
                <td> @Html.HiddenFor(model => model[i].ContactID)</td>
                <td>@Html.EditorFor(model => model[i].ContactPerson)</td>
                <td>@Html.EditorFor(model => model[i].Contactno)</td>
                <td>@Html.EditorFor(model => model[i].EmailID)</td>
            </tr>
        }
    </table>
    <p><input type="submit" value="Save" /></p>
    <p style="color:green; font-size:12px;">
        @ViewBag.Message
    </p>
}
 @section Scripts
     {@Scripts.Render("~/bundles/jqueryval")}

Code: @Scripts.Render("~/bundles/jqueryval") will enable client side validation. Finally, Run Application. Edit Contact Details and Click Save button.



HostForLIFE.eu Proudly Launches Hosting with SiteLock Malware Detector

clock October 6, 2014 06:29 by author Peter

HostForLIFE.eu, a leading Windows web hosting provider with innovative technology solutions and a dedicated professional services team, today announced the support of SiteLock Malware Detector on all their newest hosting environments. HostForLIFE.eu Hosting with SiteLock Malware Detector plan starts from just as low as $36.00 / year only and this plan has supported daily malware scan, trust seal, application scan, TrueSpeed CDN, etc.

HostForLIFE.eu offers the greatest performance and flexibility hosting with SiteLock Malware Detector at an economical price. HostForLIFE.eu provides flexible hosting solutions that enable their company to give maximum uptime to customer. SiteLock monitors your website 24x7 for vulnerabilities and attacks, which means you can worry less about your website and more about your business.

SiteLock is a cloud-based, website security solution for small businesses. It works as an early detection alarm for common online threats like malware injections, bot attacks etc. It not only protects websites from potential online threats, but also fixes vulnerabilities. With the presence of SiteLock, your website will be protected and scanned against viruses, spyware, malware, identity theft and other online scams. Note that, as they rely more and more on internet technology, these online viruses and scams become bigger and smarter to handle.

Over 70% Customers look for a sign of security before providing personal details online. The SiteLock Trust Seal not only re-assures customers, but also boosts sales. The customer doesn’t need technical ability to install and set up SiteLock for their website. SiteLock is cloud-based and starts scanning website and email instantly.
With this SiteLock feature, you can be assured that you will always be one step ahead of online hackers and swindlers’ illegal intentions. With more than 6 years in the web hosting business, HostForLIFE’s technical staff is more than ready on its feet to develop and tackle viruses, malware and the likes to sustain the safe and reliable use of your website.

Further information and the full range of features hosting with SiteLock Malware Detector can be viewed here http://www.hostforlife.eu/Hosting-with-Sitelock-Malware-Detector-in-Europe



ASP.NET MVC 6 Hosting Europe - HostForLIFE.eu :: Creating Hybrid SPA with ASP.NET MVC, WebAPI and AngularJs

clock October 2, 2014 08:10 by author Peter

The main benefit I see in following the SPA design principles for developing rich, complex web applications is the “stateful”ness we get. For complex web application, it may be too idealistic to have just one “full” initial HTTP request to get a page, and then subsequent async calls to load further pages or data. However, we can do it module-wise i.e. certain parts of the web app follow SPA design, others may or may not follow SPA design. This is referred to as mini-spa or hybrid spa. Using AngularJs in ASP.NET MVC 6 Hosting, I have come up with a sample application which follows SPA design principles. I’m using angular route module ngRoute along with angular directive ngView to define routes – controller & view associated with each route. It is essentially MVC pattern on the client-side. Moreover, our app is now route-driven on client-side. (The browser back and fro buttons are supported)

In the sample web app, we have 2 modules. In each module, user can filter results and view/edit the record. [NOTE: using mvc music store database from CodePlex.

For each module, I've defined corresponding angular module :
ngModule musicAlbumsApp for music module
ngModule movieDvdsApp for movie module

Route configuration for music module

(function (app) {
    var routeConfig = function ($routeProvider) {
        $routeProvider.when("/", {
            controller: "musicAlbumListController",
            templateUrl: window.miniSpaApp.rootUrl + "MusicAlbums/List",
            reloadOnSearch: false
        }).when("/:genreId", {
            controller: "musicAlbumListController",
            templateUrl: window.miniSpaApp.rootUrl + "MusicAlbums/List",
            reloadOnSearch: false
        }).when("/Detail/:id", {

            controller: "musicAlbumDetailController",
            templateUrl: window.miniSpaApp.rootUrl + "MusicAlbums/Detail",
            reloadOnSearch: false        }).when("/Edit/:id", {
            controller: "musicAlbumEditController",
            templateUrl: window.miniSpaApp.rootUrl + "MusicAlbums/Edit",
            reloadOnSearch: false
        }).otherwise({ redirectTo: "/" });
    };
    routeConfig.$inject = ['$routeProvider'];
    app.config(routeConfig);
})(angular.module("musicAlbumsApp"));

Each route maps to an angular controller and a view/template. 

In our main page (MusicAlbums - Index View), we include the angular scripts and define our container div using ngView directive to load different views

@section HeadContent
{
   @Scripts.Render("~/bundles/angularMusicAlbums")
}
<div data-ng-app="musicAlbumsApp" data-ng-view="" data-ng-cloak="">
</div>


Similarly, for movie module we've defined it's route configuration and container div using ngView directive.



European ASP.NET MVC 5 Hosting - UK :: How to Fix Error Could not load file or assembly 'Microsoft.Web.Infrastructure'

clock September 24, 2014 07:39 by author Scott

We believe that some of you get this error when deploying your ASP.NET MVC 5 to shared hosting:

[FileNotFoundException: Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]

Previously, we have written blog about how to deploy your MVC to shared hosting environment. In this tutorial, we will be more focusing on above error message.

This is also one of a few component libraries that are needed for deploying an MVC application:

  • System.Web.Helpers.dll (required by the web.config)
  • System.Web.Mvc.dll
  • System.Web.Razor.dll
  • System.Web.WebPages.dll
  • System.Web.WebPages.Razor.dll
  • Microsoft.Web.Infrastructure.dll

The system libraries are installed with .NET 4, however, 'Microsoft.Web.Infrastructure.dll' is only installed when Visual Studio is installed on the machine.  Therefore, short of needing to install MVC and Visual Studio on a production environment, we need to deploy the libraries with out application - and we'd like to do so automatically.

There are a few ways to automatically deploy the 'Microsoft.Web.Infrastructure.dll' component library with your application.  The steps depend on which version of Visual Studio you are using.

1. Right-click on your project and select "Add Deployable Assemblies" and you'll see the following dialog:

2. When deploying for MVC, only choose the first option.  Never mind the second option even though it says "Razor syntax." The second option is for deploying the required libraries for projects officially known today as ASP.NET Web Pages. Once you click OK, you'll see a new folder appear in your project called _bin_deployableAssemblies with the required libraries.

For .NET, this is a special folder:

  • This is a secondary bin folder for framework dependencies.  If you right-click on any one of the .dll's shown in this folder, you'll see that the libraries are set to "Copy to Output Directory".  When the application is packaged/deployed, the libraries (and the folder) are also copied.  Again, the framework will also automatically check this folder for dependencies.
  • For .NET, any folder that begins with an underscore ("_") is considered private and non-accessible to the browser.  Therefore, you can rest knowing that the dependencies are secure.

Note that this process did not add any references to these libraries in your project.  They are simply here for the framework to run your MVC application.  If you do, in fact, need a type or class from one of these libraries, you are free to still add it as a reference as you normally would.

The above method is for Visual Studio 2010. How about in Visual Studio 2012? Then, please stay here, don’t exit from our blog. We almost finish our tutorial. Stay focus. :)

After Visual Studio 2010, the "Add Deployable Assemblies" option was removed from the project's options menu.  The system libraries are automatically copied to the Bin folder of your project. However, again, the 'Microsoft.Web.Infrastructure.dll' is only available on machines that have Visual Studio installed.  So how do you deploy this library with you application if you don't want to install Visual Studio on a production environment?  I'm glad you asked.  You'll need to use the Package Manager.

1. Run the following command in the package manager (if you're not familiar with Visual Studio, this can be reached by going to "Tools --> Library Package Manager --> Package Manager Console" in the top menu).

2. At the PM> prompt type

Install-Package Microsoft.Web.Infrastructure

3. You will see then see a message indicating that it has been installed and added to your project.

4. You'll also see that 'Microsoft.Web.Infrastructure.dll' has been added as a reference in your References folder.

5. Finally, now, when you deploy your application, 'Microsoft.Web.Infrastructure.dll' will be included in the Bin folder.

Conclusion

We hope with tutorial above, you can easily deploy your MVC application without any problem. If this article, please share it!! Please tell the world. :)



ASP.NET MVC 6 Hosting - HostForLIFE.eu :: How to Solve HTTP Error 403.14 and Error 404 When Deploying ASP.NET MVC 6 website on IIS

clock September 17, 2014 08:59 by author Peter

I have build a ASP.NET 4.5 and ASP.NET MVC 6 web app which works fine locally (IIS Express & dev server) but once I deploy it to my web server, sometimes it throws Error:

  • 403.14 - Forbidden (The Web server is configured to not list the contents of this directory.)
  • 404 - Not Found (The resource you are looking for has been removed, had its name changed, or is temporarily unavailable)

SOLUTION

  • Make sure the Application pool targets correct version of .NET framework (i.e .NET Framework v4.0.30319 for .NET 4.5 and 4.5.2)
  • Make sure You have setup the website as an application in IIS
  • Make sure the Pipeline mode of IIS Application pool is "Integrated"
  • Check UrlRoutingModule-4.0 is added in the modules of that website.
  • (To do that, open list of added modules by clicking "Modules" against your website, and see if the module "UrlRoutingModule-4.0" is added or not). If not, then add a module by clicking "Add Managed Module" button, where select System.Web.Routing.UrlRoutingModule as a Module type, and give "UrlRoutingModule-4.0" as its name)
  • Make sure you have following element added in system.webServer section of website's web.config

<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules> 
</system.webServer>

In most cases of HTTP Error 403.14, or 404, above are the possible causes and fixes. 



ASP.NET MVC 6 Hosting - HostForLIFE.eu :: Displaying Validation Errors with ASP.NET MVC

clock September 9, 2014 09:33 by author Peter

We all know how important it is to validate user input, but it’s equally important how we present validation errors to the user. Take the following form you can see below:

The email field needs to be optional but any address entered must be valid. If a validation error occurs, it should replace the optional label with the error message. Behind the scenes I’m using Data Annotations to validate the email address, so any errors will be passed into the ModelState. ASP.NET MVC 6 has built-in support for showing these errors (using the ValidateMessageFor helper) so it’s easy to write a wrapper around that, supplying the ‘optional’ text as a parameter.

Here’s an extension method for the HtmlHelper:
public static class ExtensionMethods

{
 public static MvcHtmlString HelpMessageFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, string helpText)
{
        var validation = htmlHelper.ValidationMessageFor(expression);
        if (validation == null)
            return new MvcHtmlString("<span class='help-inline muted'>" + helpText + "</span>");
        else
            return validation;
    }
}

Here’s it’s usage:

<fieldset>
  <div class="control-group">
        @Html.LabelFor(x => x.EmailAddress, "Email", new { @class = "control-label" })
        <div class="controls">
            @Html.TextBoxFor(x => x.EmailAddress, new { @class = "input-xlarge", placeholder = "Enter an email address" })
            @Html.HelpMessageFor(x => x.EmailAddress, "Optional")
        </div>
    </div>
</fieldset>



European HostForLIFE.eu Proudly Launches WordPress 4.0 Hosting

clock September 1, 2014 09:14 by author Peter

HostForLIFE.eu proudly launches the support of WordPress 4.0 on all our newest Windows Server environment. On WordPress 4.0 hosted by HostForLIFE.eu, you can try our new and improved features that deliver extremely high levels of uptime and continuous site availability start from €3.00/month.

WordPress is a flexible platform which helps to create your new websites with the CMS (content management system). There are lots of benefits in using the WordPress blogging platform like quick installation, self updating, open source platform, lots of plug-ins on the database and more options for website themes and the latest version is 4.0 with lots of awesome features.

WordPress 4.0 was released in August 2014, which introduces a brand new, completely updated admin design: further improvements to the editor scrolling experience, especially when it comes to the second column of boxes, better handling of small screens in the media library modals, A separate bulk selection mode for the media library grid view, visual tweaks to plugin details and customizer panels and Improvements to the installation language selector.

HostForLIFE.eu is a popular online WordPress 4.0 hosting service provider catering to those people who face such issues. The company has managed to build a strong client base in a very short period of time. It is known for offering ultra-fast, fully-managed and secured services in the competitive market.

Another wonderful feature of WordPress 4.0 is that it uses vector-based icons in the admin dashboard. This eliminates the need for pixel-based icons. With vector-based icons, the admin dashboard loads faster and the icons look sharper. No matter what device you use, whether it’s a smartphone, tablet, or a laptop computer, the icons actually scale to fit your screen.

WordPress 4.0 is a great platform to build your web presence with. HostForLIFE.eu can help customize any web software that company wishes to utilize. Further information and the full range of features WordPress 4.0 Hosting can be viewed here http://hostforlife.eu/European-WordPress-4-Hosting

About Company
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.



Comparison of Windows ASP.NET Hosting between HostForLIFE.eu Hosting Platform and Windows Azure Platform

clock August 25, 2014 11:13 by author Peter

Given the length of this review and the number of plans, it is unrealistic to compare everything of them one by one. As usual, the review focuses on price, features, uptime & speed as well as customer support. Before starting our detailed comparison, we’d like to share with you the overall ratings of the plans based on our first-hand hosting experience and large-sampled customer reviews.

Please refer to this table for more differences and similarities.

 


HostForLIFe.EU

Windows Azure

 

 

 

Price

€3.00/month

$76 / month

Website

Unlimited

100

Disk Space

Unlimited

1 GB

Bandwidth

Unlimited

Unlimited

1 SQL Server Size

Include 50MB

0 to 100 MB = $ 5.041/mo

Server Features

Include 4 GB RAM or higher

768 MB = $16/month

SLA

99.90%

99.90%

ASP.NET 4.5.2 / ASP.NET 4.5.1

Yes

Yes

ASP.NET 4.5 / ASP.NET 4.0

Yes

Yes

ASP.NET 3.5 / ASP.NET 2.0 / ASP.NET 1.1

Yes

Yes

Classic ASP

Yes

Yes

ASP.NET MVC 6.0 / 5.2 / MVC 5.1.2 / MVC 5.1.1 / MVC 5.0

Yes

Yes

ASP.NET MVC 4.0 / MVC 3.0 / MVC 2.0

Yes

Yes

WordPress

Yes

Yes

Umbraco

Yes

Yes

Joomla

Yes

Yes

Drupal

Yes

Yes

Node.js

Yes

Yes

PHP 5

Yes

Yes

Conclusion
Both companies are able to provide brilliant Windows hosting service. If a choice has to be made, we recommend HostForLIFE.eu as your web host because the price is more reasonable, features more complete and the performance and our technical support are awesome.To learn more about HostForLIFE.eu web hosting, please visit http://www.hostforlife.eu



European ASP.NET MVC 5 Hosting - UK :: How to Use Post Redirect and Get Pattern

clock August 15, 2014 05:44 by author Onit

Note: This post has been updated to work with MVC 2 RTM. You can Use POCO,  but the workflow is what you should be mostly concerned about. 

The ASP.NET MVC pattern tends to lead itself into a more simplified and "true" HTTP experience by re-introducing  patterns that have been lost, or at least, not followed in many years. One such pattern is the Post, Redirect, Get (PRG) pattern in which it is "to help avoid duplicate form submissions and allow web applications to behave more intuitively with browser bookmarks and the reload button".

A normal ASP.NET Web Form Lifecycle has the following pattern

  1. HTTP GET of "Create.aspx"
  2. HTTP POST of "Create.aspx"
  3. Validation Fails, "Create.aspx" is Re-Rendered
  4. HTTP POST of "Create.aspx"
  5. Item is created, "Create.aspx" is Re-Rendered with confirmation message

The major problems with this Postback pattern, is that hitting the Refresh button of your browser in steps 3 or 5 will re-post your submitted data. Step 5 is more of a problem as it could possibly re-submit that created information. Granted, there are steps that you can take to approach this problem, but this is how default ASP.NET Web Forms are treated.

Taking this same approach within ASP.NET MVC, can be achieved in the same manner by rendering a your "Create" view from your POST action. For example:

  1. HTTP GET of "/products/create", "Create" view is rendered
  2. HTTP POST to "/products/submit"
  3. Validation Fails, "Create" view is rendered
  4. HTTP POST to "/products/submit"
  5. Item is created, "Confirm" view is rendered

As you'll notice, the same problems we had with ASP.NET Web Forms exists with ASP.NET MVC. The really nice option, is that ASP.NET MVC gives you a lot more "freedom" of how the workflow is processed. If we strictly follow the PRG pattern within ASP.NET MVC, it would look something like

HTTP GET of "/products/create", "Create" view is rendered
HTTP POST to "/products/submit"
Validation Fails, redirect to "/products/create", "Create" view is rendered
HTTP POST to "/products/submit"
Item is created, redirect to "/products/confirm", "Confirm" view is rendered

As you'll notice, where we previously could have had issues in step 3 or 5 before, we no longer have issues. If a user presses the Refresh button in either of those steps, they'll not get the lovely "Would you like to resubmit the form data" confirmation as featured below - instead, the page just reloads.

To implement this, you'll need 1 controller, 3 action methods, and 2 views. Follow the steps below to achieve this pattern:

When you implement your Create action, you have to keep in mind that validation may fail and you may need to re-display the form. TempData is best suited for this scenario, and is implemented as such.



Next you'll implement your Submit action. This will perform some validation of the user input data, and if successful will save the info and redirect to the Confirm action. If it is not successful, we'll store the form data into the TempData and redirect to the action Create. This way we mimic maintaining the view's state even if it fails.



Something very interesting to note in the above example, is that even though I've pulled all values out of the form into local variables, should either Price or Quantity fail in parsing and I set the TempData to the local variables...I would have lost the user input. So, it's always a smart idea to retrieve the data from the form directly into the TempData. Finally, the Confirm action needs to be implemented.

public ActionResult Confirm()
  {
      return View();
  }

Now, it's time to create our views:

~/Views/Products/Create.aspx

~/Views/Products/Confirm.aspx



And that's it. As you can see from the Create view, when writing our textboxes, we give them a default value from the ViewData.



About HostForLIFE

HostForLIFE is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2019 Hosting, ASP.NET 5 Hosting, ASP.NET MVC 6 Hosting and SQL 2019 Hosting.


Month List

Tag cloud

Sign in