【问题标题】:aspx to mvc microsoft visual studio 2012aspx 到 mvc 微软视觉工作室 2012
【发布时间】:2013-06-03 18:50:29
【问题描述】:

我不知道如何将此代码更改为 MVC, 有人可以帮我做 它或解释我该怎么做,

这是关于修改编辑和 删除数据库的一个组件

我需要理解它并在 3 天内完成。非常感谢:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="1_DetailsView.aspx.cs"          Inherits="GridView_Edit._1_DetailsView" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title></title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
    <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="299px" 
        AutoGenerateRows="False" DataKeyNames="idL" DataSourceID="SqlDataSource1" 
        AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None">
        <AlternatingRowStyle BackColor="White" />
        <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
        <EditRowStyle BackColor="#2461BF" />
        <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
        <Fields>
            <asp:BoundField DataField="idL" HeaderText="idL" InsertVisible="False" 
                ReadOnly="True" SortExpression="idL" />
            <asp:BoundField DataField="krstne" HeaderText="krstne" 
                SortExpression="krstne" />
            <asp:BoundField DataField="spec" HeaderText="spec" SortExpression="spec" />
            <asp:BoundField DataField="datNar" HeaderText="datNar" 
                SortExpression="datNar" />
            <asp:CommandField ShowEditButton="True" />
            <asp:CommandField ShowInsertButton="True" />
            <asp:CommandField ShowDeleteButton="True" />
        </Fields>
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" />
    </asp:DetailsView>
    <!-- Datum sa neUpdejtuje ;) -->
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:PoliklinikaConnectionString3 %>" 
        SelectCommand="SELECT * FROM [Lekari]"
        UpdateCommand="Update [Lekari] SET krstne=@krstne, spec=@spec WHERE idL=@idL" 
        InsertCommand="Insert [Lekari] Values(@krstne, @spec, @datNar)"
        DeleteCommand="Delete [Lekari] Where  idL=@idL"
        ></asp:SqlDataSource>

   </div>
   </form>
 </body>
</html>

【问题讨论】:

  • 如果这只是直接与数据库表相关的项目的编辑/删除功能,那么您可以在 ASP.NET MVC 中使用大多数开箱即用的功能来实现它。从 Nerd Dinner 教程开始,了解 ASP.NET MVC 的工作原理。如果您期望从 WebForms 到 MVC 的逐行转换,那么您将导致比您解决的问题更多。

标签: asp.net-mvc asp.net-mvc-3 model-view-controller


【解决方案1】:

MVC 是一种完全不同的构建 Web 应用程序的方法。最大的不同是取消了 Web 控件,取而代之的是更轻量级的 HTML 助手。既然您问这个问题,我假设您可能需要更好地了解 MVC,以便了解如何获取现有 Web 窗体应用程序的业务需求,并将它们应用到 MVC 应用程序。

我知道您的时间有限,但我建议您通过this tutorial。在没有这种程度的理解的情况下试图匆忙找到解决方案只会对你自己和你的客户造成伤害。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-04
    • 2015-09-29
    • 2014-12-28
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多