Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Entity Framework 101
Message
De
04/06/2014 10:19:17
 
 
À
04/06/2014 10:15:27
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Versions des environnements
Environment:
C# 4.0
OS:
Windows 8
Network:
Windows 2000 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01601183
Message ID:
01601265
Vues:
30
The code you posted is View code. Database access doesn't belong in the View. We'll keep this simple instead of best-practice.

The View will talk to the Controller. The Controller instantiates the context and talks to it.


>Can you help me fit that code into this, please?
>
>
@model IBCPackageTracking.Route
>
>@{
>    ViewBag.Title = "Route";
>}
>
><h2>Get Run Sheet for your Route</h2>
><div class="content">
>    <div class="float-left">
>        <select id="SelectRoute" data-bind="options: routes, optionsText: 'rte_name', optionsCaption: 'Select a Route', optionsValue: 'rte_pk'">
>        </select>
>        <p>Date: <input type="text" id="datepicker"></p>
>        <div><input type="submit" value="Get Run Sheet" /></div>
>    </div>
>
></div>
>@section Scripts {
>    @Scripts.Render("~/bundles/jqueryval")
><link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
>
><script src="//code.jquery.com/jquery-1.10.2.js"></script>
><script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
><link rel="stylesheet" href="/resources/demos/style.css">
><script>
>    $(function () {
>        $("#datepicker").datepicker();
>    });
></script>
>
>    <script type="text/javascript" src="@Url.Content("~/Scripts/knockout-2.2.0.js")"></script>
>    <script type="text/javascript">
>        // View-model will go here
>        function RoutesViewModel() {
>            var self = this;
>            self.routes = ko.observableArray();
>
>            var baseUri = '@ViewBag.ApiUrl';
>
>            self.create = function (formElement) {
>                // If the form data is valid, post the serialized form data to the web API.
>                $(formElement).validate();
>                if ($(formElement).valid()) {
>                    $.post(baseUri, $(formElement).serialize(), null, "json")
>                        .done(function (o) {
>                            // Add the new product to the view-model.
>                            self.routes.push(o);
>                        });
>                }
>            }
>
>            self.update = function (route) {
>                $.ajax({ type: "PUT", url: baseUri + '/' + route.Id, data: route });
>            }
>
>            self.remove = function (route) {
>                // First remove from the server, then from the view-model.
>                $.ajax({ type: "DELETE", url: baseUri + '/' + route.Id })
>                    .done(function () { self.products.remove(route); });
>            }
>
>            $.getJSON(baseUri, self.routes);
>            
>        }
>
>        $(document).ready(function () {
>            ko.applyBindings(new RoutesViewModel());
>        })
>    </script>
>}
>
>
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform