MVCToolkit, 我从网上下来的,那个是ms  出的mvc 框架,我怎么编译有错误啊。
错误 1
找不到类型或命名空间名称“ChangeAction”(是否缺少 using 指令或程序集引用?)
E:\ODP.NET samples\文档\MVCToolkit\Blog\Models\ModelPartials.cs还有好几个,大家帮我看看

解决方案 »

  1.   

    楼主你的编译不过是因为你机子上装的是:AspNetMVCPreview2-setup.msi(第二预览版) 而不是ASPNetExt.exe(里面包括MVC第一预览版)即你下载的 MVCToolkit 只能配合 第一预览版使用(只有在装有 ASPNetExt.exe的VS2008中才能编译通过)不过我自己也有一点郁闷,在AspNetMVCPreview2 中 引用的System.Web.Extensions 是 3.5版的 而在MVCToolkit中引用的是3.6版的 也就是说低版本的MVC引用的 System.Web.Extensions 的版本反尔高 ,我晕,我把MVCToolkit用在第二预览版中死活不行。因为俺想用里面的 UpdateFrom 方法,我在第二预览版中没有找到类似的方法,不知道各位有没有好的方法。-----------
    在这里顺便问个问题,就是在第一预览版中,在控制器的Action方法中 可以用如下语句来跳转带ID等参数的URLRedirectToAction(new { Action = "Category", id = product.CategoryID });在第二预览版中反尔不能这样写了,不知道各位是如何来解决这个问题的。
      

  2.   

    上面的答案已找到:第一预览版写法:
    RedirectToAction(new { Controller="Products",Action = "Category", id = product.CategoryID }); 第二预览版写法:  System.Web.Routing.RouteValueDictionary rvd=new System.Web.Routing.RouteValueDictionary();
      rvd.Add("Controller","Products");
      rvd.Add("Action","Category");
      rvd.Add("id",product.CategoryID);
      RedirectToAction(rvd); 也可以简写成下面一句:
         RedirectToAction(new RouteValueDictionary { {"Controller" ,"Products"},{"Action" ,"Category"} ,{"ID",product.CategoryID}});
      

  3.   

    如果按照网上思归提供的教程去做,在第二预览版中 可能都不需要MVCToolKit了因为在第一预览版中,那个例子只用到了MVCToolKit里的两个功能,
    (1)是: 在页面显示时用到 HTML的扩展功能 例:Html.TextBox(); 在第一预览版中如果不引用MVCToolkit.dll的话 Html 是点不出TextBox等方法的。
    但在第二预览版中MVC中已经对这个进行了扩展,所以不需要引用 MVCToolkit.dll(2)是:在控制器接收表单的值传给对象属性时 用到的 UpdateFrom 方法 例如下:
          Product product = northwind.GetProductById(id); //Product 是用Linq To Sql 生成的实体类
          product.UpdateFrom(Request.Form); (product)
         northwind.SubmitChanges();     这两句代码就可以把表单的值付给product的属性,并提交保存到数据库      在第二版预览版中不知道为什么没有把这个方法 也加到 MVC中 (我想可能是因为此方法容易出错且面向对象的概念不强的原故吧)      不过俺从MVCToolkit中把UpdateFrom复制到我的项目中改了一下编译后同样可以用了。代码如下:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Reflection;
    using System.ComponentModel;
    using System.Collections.Specialized;namespace MyShopAdd2.Controllers
    {
        public static class BindingHelperExtensions
        {
            /// <summary>
            /// Reads in values from a NameValueCollection (like Request.Form, Cookies, Session, or QueryString) and sets the properties
            /// on this object. The names of the values must be Type.PropertyName - i.e. "Product.ProductName"
            /// </summary>
            /// <param name="values">Request.Form, QueryString, Parameter, etc</param>
            public static void UpdateFrom(this object obj, NameValueCollection values)
            {
                UpdateFrom(obj, values, "");
            }
            /// <summary>
            /// Reads in values from a NameValueCollection (like Request.Form, Cookies, Session, or QueryString) and sets the properties
            /// on this object. The names of the values must be Type.PropertyName - i.e. "Product.ProductName"
            /// </summary>
            /// <param name="values">Request.Form, QueryString, Parameter, etc</param>
            /// <param name="objectPrefix">A prefix for the Keys in the Namevalue collection - "Product." in "Product.ProductName" for example</param>
            public static void UpdateFrom(this object obj, NameValueCollection values, string objectPrefix)
            {
                Type objType = obj.GetType();
                string objName = objType.Name;                        PropertyInfo[] fields = objType.GetProperties();
                            foreach (PropertyInfo property in fields)
                {                //check the key
                    //going to be forgiving here, allowing for full declaration
                    //or just propname
                    string httpKey = property.Name;                if (objectPrefix != string.Empty)
                        httpKey = objectPrefix + httpKey;                if (values[httpKey] == null)
                    {
                        httpKey = objName + "." + property.Name;
                    }                if (values[httpKey] == null)
                    {
                        httpKey = objName + "_" + property.Name;
                    }
                    if (values[httpKey] != null)
                    {
                        TypeConverter conv = TypeDescriptor.GetConverter(property.PropertyType);
                        object value = values[httpKey];                    if (conv.CanConvertFrom(typeof(string)))
                        {
                            try
                            {
                                value = conv.ConvertFrom(values[httpKey]);
                                property.SetValue(obj, value, null);                        }
                            catch (Exception e)
                            {
                               
                                throw new Exception(property.Name + " is not a valid " + property.PropertyType.Name + "; " + e.Message);                        }
                        }
                        else
                        {
                            throw new Exception("No type converter available for type: " + property.PropertyType);
                        }
                    }
                }
               
            }        // --------- Class End ---------
        }
    }
      

  4.   

    晕,是去年12月份的贴子啊。我本来想找问题的解决方法的,在google搜了一下,看到这个贴子就回了,现在才看到是去年12月份的。