3

これが私の見解です

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="InsertUser.aspx.cs" Inherits="WebApplication1.InsertUser" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"></asp:ObjectDataSource>

        <asp:TextBox></asp:TextBox> // i want to bind the Fullname Property here
        <asp:Button></asp:Button> // i want to bind the Save() here
    </div>
    </form>
</body>
</html>

ビューモデルからプロパティとメソッドをバインドしたいと思います。出来ますか?

これは私のViewModelです

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Services;

namespace Testing.ViewModel
{
    public class UserVM
    {
        public int UserID { get; set; }
        public string Fullname { get; set; }

        [WebMethod]
        public void Save()
        {

        }
    }
}

誰かが私を正しい方向に導くことができますか? Grid を ObjectDataSource にバインドでき、CRUD 操作を実行できますが、View を ViewModel にバインドできません。

これは、CRUD操作を使用したViewModelからグリッドを使用したビューへの私のサンプルバインディングです

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title></title></head><body><form id="form1" runat="server">
    <div>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="Testing.Model.User" DeleteMethod="DeleteUser" InsertMethod="CreateUser" SelectMethod="GetUsers" TypeName="Testing.ViewModel.UserListVM" UpdateMethod="UpdateUser"></asp:ObjectDataSource>
        <asp:GridView ID="GridView1" DataSourceID="ObjectDataSource1" runat="server" AllowPaging="True" AutoGenerateColumns="False">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
                <asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" />
                <asp:BoundField DataField="Fullname" HeaderText="Fullname" SortExpression="Fullname" />
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>

UserListVM

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Testing.Model;
namespace Testing.ViewModel
{
    public class UserListVM
    {
        public UserListVM()
        {
        }
        public IEnumerable<User> GetUsers()
        {
            return VMIndex.Users;
        }
        public User UpdateUser(User user)
        {
            throw new NotImplementedException();
        }
        public User DeleteUser(User user)
        {
            throw new NotImplementedException();
        }
        public User CreateUser(User user)
        {
            throw new NotImplementedException();
        }
    }
}

助けてください..よろしくお願いします。

4

0 に答える 0