保存前带有预览的MVC3表单 [英] MVC3 Form with Preview before save

查看:67
本文介绍了保存前带有预览的MVC3表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发MVC3上的应用程序,并且:

I'm currently developing an application on MVC3 and:

  1. 我有一个表单,用户在其中填写每个表单 注册.
  2. 当他单击一个按钮时,记录将传递到控制器 并存储在列表中,然后再次传递到视图以显示 预览缓冲区"中的内容
  3. 为了避免其消失而未编辑且仅显示的数据(先前的寄存器)通过使用hiddenfor的多个步骤得以保存
  4. 最后,当单击另一个按钮时,用户可以将列表中的所有元素保存在数据库中
  1. I have a form in which the user is completing the form for each register.
  2. When he click one button the records are passed to the controller and stored in a list and then passed to the view again to show a preview of what is at the momment in the "buffer"
  3. The data which is not edited and only displayed (previous registers) for avoiding their dissapear are preserverd in the multiple steps using hiddenfor
  4. Finally the user can save all the elements on the list in the database when click another button

我的问题是:有没有一种方法可以保存列表中的数据,而不必为每个步骤中的每个元素都隐藏一个?

My question is: there is way to preserving the data in the list without having to make a hiddenfor for every element in each step?

推荐答案

我认为您可以使用向导技术来执行此操作.因此,首先您需要找到一个向导插件. 例如 jQuery步骤. 每一步都有您需要的表格,您有两种选择: 像这样与Session一起工作:

I think you can use wizard technique to do this .So first you need to find an wizard plugin. For example jQuery steps. One each step you will have form that you need and the you have two choices: to work with Session like this :

   public YourObject GetObjectfromSession()
            {
                var obj = new YourObject();
                if (HttpContext.Session["SessionName"] != null)
                {
                    obj= (VmSysMealCreate)HttpContext.Session["SessionName"];
                }
                return obj;
            }

            public void InsertObjectTOSession(YourObject obj)
            {
                HttpContext.Session.Add("SessionName", obj);
            }

在更改的每个步骤中,您都可以验证表单并将其提交给控制器中的方法,在该方法中,您可以将其保存到数据库中,而不是保存到会话中.最后一步,您可以为表单中的所有内容做一个摘要. 这是一个很好的解决方案,将很容易实现并且可以很好地工作.但是使用此解决方案时,您需要考虑会话需要保存多长时间来保存数据,因为会话会受到时间的限制.

On each step changing you can validate form and submit it to method in controller where you will save this not to database but to session.And on final step you can make a summary for all you form . This is good solution ,this will be very easy to implement and will work nice.But using this solution you need to think about how long you need session to save your data because session will be limited in time.

您可以做的第二件事: 使用向导插件,在最后一步,您可以获得所有表格,对于每种表格,您都可以执行以下操作:

Second thing that you can do : Using an wizard plugin, on last step you can get all your forms and for each form you can do something like this:

function functionNAme(formId) {

    var form = jQuery("#" + formId);
 if (form.valid()) { //If form is valid
        form.submit();
        return isValid;
    }
    var isValid = false;

    form.submit(function (e) {
        var that = this;
        jQuery.ajax({
            url: this.action,
            type: this.method,
            data: jQuery(this).serialize(),
            async: false,
            /* cache: false,*/
            success: function (result) {
               //on post method return result (summary view ofr each form )
              //and you can append it to your last step
                }
                return false;
            }
        });
        // unbind form submit event
        form.unbind(e);
        // preventing default
        e.preventDefault();
        // cancel the default submission of the form
        return false;
    });   
}

第二个解决方案很好,但实施起来并不容易 希望这会帮助您,并且您会做出正确的决定.如果您找到其他解决方案,请向我们提供.

Second solution is good but is not so simple to implement Hope this will hoe you and you will make right decision.If you will find anther solution please provide us with it.

这篇关于保存前带有预览的MVC3表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆