C# 插入更新删除web GUI

C# 插入更新删除web GUI,c#,html,web,C#,Html,Web,我发现自己经常创建添加/编辑/删除/列表GUI,对此我感到厌倦。 一定有免费的软件包可以解决这个问题,对吧 我想要的是这样的: { MyApplicationUser user = MyApplication.GetUserByID(1234); EditForm form = new EditForm("Title: Edit User"); //this is the magic object form.addFieldsFromObject(user); }

我发现自己经常创建添加/编辑/删除/列表GUI,对此我感到厌倦。 一定有免费的软件包可以解决这个问题,对吧

我想要的是这样的:

 {
    MyApplicationUser user = MyApplication.GetUserByID(1234);
    EditForm form = new EditForm("Title: Edit User"); //this is the magic object

    form.addFieldsFromObject(user);
 }


 function onFormSubmit(eventArgs e){
     MyApplicationUser user = form.GetSubmittedData();
     MyApplication.SaveUser(user);
 }

AddFieldsFromObject
将自动创建一个html表单,其中的字段与我提供给它的对象的公共属性的数据类型匹配。

有许多框架试图解决这个问题。也许是个好的开始。它使用一个基于模板的系统来提供基本的CRUD(创建、检索、更新、删除)用户界面,只需极少的自定义代码

ASP.NET MVC在编辑器模型方面也做得很好:

// View code
@using(Html.BeginForm(...)) {
    @Html.EditorForModel()
}

// Action code
public ActionResult ShowForm(int userId)
{
    var model = // get model from user ID;
    return View(model);
}


public ActionResult SaveForm(Model model)
{
    if(ModelState.IsValid)
    {
        // Save model
    }
}

尝试通过自动生成基本的脚手架代码来解决同样的问题,从而产生类似于Microsoft Access的体验。但是由于它使用的是实际的C代码,如果您发现您的需求超出了项目的原始范围,您可以修改代码以提供更多功能。

看看MVCSCapfolding-