使用MVC3将内容添加到数据库

时间:2012-07-05 17:44:23

标签: c# asp.net asp.net-mvc-3

我有一些存储过程已经向数据库添加信息。现在我正在创建一个允许用户查看数据库中某些项目的网页。当用户查看页面时,他或她可以选择编辑/更新或添加新商家。我在控制器中遇到困难,我的方法没有接受我给它的参数。如果您有任何线索或知道答案请分享..谢谢

P.S Whener我将鼠标悬停在添加功能上 bool MerchantTypeRef.addMerchantTypeRef(MerchantAdminProductionServices.MerchantTypeRef merchantTypeRef)

错误:   “MerchantAdministrator.Models.MerchantAdminProduction.MerchatTypeRef.addMerchantTypeRef(MerchantAdministrator.MerchantAdminProductionServices.MerchantTypeRef)”的最佳重载方法匹配具有一些无效参数

控制器

 [MerchantAuthorizeAttribute(AdminRoles = "AddMerchantTypeRef")]
    public ActionResult AddMerchantTypeRef()
    {
        try
        {
            Guid merchantTypeRefId = Request["merchantTypeRefId"] != null ? new Guid(Request["merchantTypeRefId"]) : Guid.Empty;
               string name = Request["name"]?? string.Empty;
            string description = Request["description"]?? string.Empty;
            string xMerchantType = Request["xMerchantTypeRefCode"]??string.Empty;
            DarkstarAdministrator.DarkstarAdminProductionServices.MerchantTypeRef merchantTypeRef = new DarkstarAdministrator.DarkstarAdminProductionServices.MerchantTypeRef();

            merchantTypeRef.name = name;
            merchantTypeRef.description = description;
            merchantTypeRef.xMerchantTypeCode = xMerchantType;
           ViewBag.addMerchantTypeRef = MerchantAdministrator.Models.MerchantAdminProduction.MerchantTypeRef.addMerchantTypeRef(merchantTypeRef);  <------This where I have the Trouble . not reading parameter
        }
        catch (Exception e)
        {
            Commons.ErrorHandling.ReportError("MerchantAdministrator.Controllers.ProdController AddMerchantTypeRef()", e);
        }
        return View();

    }

模型

  public static bool addMerchantTypeRef(DarkstarAdminProductionServices.MerchantTypeRef merchantTypeRef)
    {
        try
        {
            DarkstarAdminProductionServices.DarkstarAdminProductionServicesSoapClient client = new DarkstarAdminProductionServices.DarkstarAdminProductionServicesSoapClient();
            return client.addMerchantTypeRef(merchantTypeRef);
        }
        catch (Exception e)
        {
            Commons.ErrorHandling.ReportError("MerchantTypeRef.addMerchantTypeRef()", e);

        }
        return false;
    }

参考

 [System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
    public System.Guid merchantTypeRefId {
        get {
            return this.merchantTypeRefIdField;
        }
        set {
            if ((this.merchantTypeRefIdField.Equals(value) != true)) {
                this.merchantTypeRefIdField = value;
                this.RaisePropertyChanged("merchantTypeRefId");
            }
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false)]
    public string name {
        get {
            return this.nameField;
        }
        set {
            if ((object.ReferenceEquals(this.nameField, value) != true)) {
                this.nameField = value;
                this.RaisePropertyChanged("name");
            }
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=2)]
    public string description {
        get {
            return this.descriptionField;
        }
        set {
            if ((object.ReferenceEquals(this.descriptionField, value) != true)) {
                this.descriptionField = value;
                this.RaisePropertyChanged("description");
            }
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=3)]
    public string xMerchantTypeCode
    {
        get {
            return this.xMerchantTypeCodeField;
        }
        set {
            if ((object.ReferenceEquals(this.xMerchantTypeCodeField, value) != true)) {
                this.xMerchantTypeCodeField = value;
                this.RaisePropertyChanged("xMerchantTypeCode");
            }
        }
    }

查看

<script type="text/javascript">
$(document).ready(function () {
    $("#merchantTypeUpdateButton").click(function () {
        $("#updateMerchantType").submit();
    });
});

编辑商家类型

<%MerchantAdministrator.MerchantAdminProductionServices.MerchantTypeRef     EditMerchantType = ViewBag.MerchantTypeRefEdit !=null ? ViewBag.MerchantTypeRefEdit: new    MerchantAdministrator.DarkstarAdminProductionServices.MerchantTypeRef(); %>
<form id="updateMerchantType" action="<%=Url.Action("EditMerchantTypePost","Prod") %>?    merchantTypeRefId"=<%=EditMerchantType.merchantTypeRefId %>" method="post">
    <table>
        <tr>
            <td colspan="3" class="tableHeader">Merchant Type Ref Details</td>
        </tr>
        <tr>
            <td colspan="2" class="label">Name:</td>
            <td class="content">
                <input type="text" maxlength="100" name="Name" value="  <%=EditMerchantType.name %>" />
        </td>
    </tr>
     <tr>
        <td colspan="2" class="label">Description:</td>
        <td class="content">
            <input type="text" maxlength="2000" name="Description" value="<%=EditMerchantType.description %>" />
        </td>
    </tr>
     <tr>
        <td colspan="2" class="label">Merchant Type Code:</td>
        <td class="content">
            <input type="text" maxlength="5" name="XMerchantTypeCode" value="<%=EditMerchantType.xMerchantTypeCode %>" />
        </td>
    </tr>
    <tr>
        <td colspan="3" class="tableFooter">
                <br />
                <a id="merchantTypeUpdateButton" href="#" class="regularButton">Save</a>
                <a href="javascript:history.back()" class="regularButton">Cancel</a>
        </td>
    </tr>
</table>

1 个答案:

答案 0 :(得分:1)

bool ViewBag.addMerchantTypeRef = MerchantAdministrator.Models.MerchantAdminProduction.MerchantTypeRef.addMerchantTypeRef(merchantTypeRef);

请告诉我这是“merchantTypeRef”还是“merchantTypeRefId”?因为merchantTypeRefId是第一行读取的内容,因此在调用Model时需要传递相同的值。如果这不起作用,你可以试试“FormCollection”吗?

相关问题