MVC3 [Required] validation message showing prior to form submission

use*_*435 2 c# validation razor asp.net-mvc-3

I have a model that has numeric and string attributes, each having the [Required] validation annotation. I also have a respective view that is an input form for this model. For some reason, as soon as the view is loaded, the required validation message for the string attribute shows immediately, as opposed to the required validation message for the numeric attribute which only shows once the user attempts to submit the form (as expected). Does anyone have a clue as to the odd validation behaviour on the string attribute?

Update

我将问题缩小到我从控制器操作显示视图的“复杂”方式。就我而言,我有一个控制器操作 Create,负责创建一个具有许多属性的实体。由于实体具有许多属性,因此我通过服务器端向导将这个过程拆分为多个步骤。以下是我的控制器操作的简化版本:

public ActionResult Create()
    {
        Model = new CreateEditListingViewModel();
        return View("StepOne");
    }

    [HttpPost]
    public ActionResult Create(string buttonValue, StepOneViewModel stepOneModel, StepTwoViewModel stepTwoModel, StepThreeViewModel stepThreeModel)
    {
        ActionResult nextView = null;
        CreateListingSteps step = (CreateListingSteps)Enum.Parse(typeof(CreateListingSteps), buttonValue);
        // Save the value of the step that has been submitted and redirect user to next step
        switch (step)
        {
            case CreateListingSteps.StepOne:
                Model.StepOne = stepOneModel;
                nextView = View("StepTwo");
                break;
            case CreateListingSteps.StepTwo:
                Model.StepTwo = stepTwoModel;
                nextView = View("StepThree");
                break;
            case CreateListingSteps.StepThree:
                Model.StepThree = stepThreeModel;
                nextView = View("Confirm");
                break;
        }
        return nextView;
    }
Run Code Online (Sandbox Code Playgroud)

显然发生的事情是,一旦用户第一次单击“下一步”按钮(在所有步骤视图中都可用),将触发所有后续表单的验证,因此即使用户尚未提交表单,字符串字段也会显示为无效.

Blank form that hasn't been submitted showing required message for description field.  Price appears regularly because its data type is not string

任何人都可以想出解决方法吗?

use*_*435 5

我解决了。我所需要的只是ModelState.Clear()在返回新视图之前调用。