English 中文(简体)
在我提交表格时,对除名人没有价值
原标题:No value for the dropdownlist when my form is submitted

在我看来,我试图利用从名单上删除的作者(用户)名单。 我能够把这一下降集中起来,并看到我的看法的内容。 我在提交我的表格时,在我的控制员中和在检查我的模型时,我不敢行动,与我的下降有关的实地价值就是无效的。

Here is my action controller (before showing my view):

    public ActionResult Create()
    {
        IEnumerable<User> authors = m_AccountBusiness.GetAllUsers();

        PageCreateViewModel viewModel = new PageCreateViewModel
        {
            PageToCreate = new PageFullViewModel(),
            Authors = authors.Select(x => new SelectListItem { Text = x.UserName, Value = x.UserID.ToString() })
        };

        return View(viewModel);
    }

下面是(部分)我的看法:

@model MyBlog.ViewModels.PageCreateViewModel

<h3>Create</h3>

@using (Html.BeginForm())
{

@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.PageToCreate.PageID)

<div class="editor-label">
    @Html.LabelFor(model => model.PageToCreate.Title)
</div>
<div class="editor-field">
    @Html.TextBoxFor(model => model.PageToCreate.Title, new { @class = "titleValue" })
    @Html.ValidationMessageFor(model => model.PageToCreate.Title)
</div>

<div class="editor-label">  
    @Html.LabelFor(model => model.PageToCreate.Author)
</div>
<div class="editor-field">      
    @Html.DropDownListFor(model => model.PageToCreate.Author, Model.Authors, "Please select...")    
</div>

我的《意见》是:

public class PageCreateViewModel
{
    public PageFullViewModel PageToCreate { get; set; }
    public IEnumerable<SelectListItem> Authors { get; set; }
}

任何想法?

感谢。

问题回答

谢谢。 最后,我发现我的错误:没有。 作者是受约束的权利财产,必须成为作者!

<div class="editor-field">           
@Html.DropDownListFor(model => model.PageToCreate.AuthorID, Model.Authors, "Please select...")         
</div> 

感谢。

You have to add an extra string property to your PageCreateViewModel. In this property we will store the selected value. Lets say it s name is "Author". Edit: I noticed you have a property for it in your model but give it a try like this.

填补下游名单需要考虑您的看法。

 @Html.DropDownList("Author", Model.Authors)




相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签