开发者

Mvc 3 form post parameter: How can I reach ddl with name="Attribute.AttributeID" by a parameter in a controller

I have a dropdownlist that looks like this:

@Html.DropDownListFor(
        x => x.At开发者_JAVA百科tribute.AttributeID,
        new SelectList(Model.Attributes, "AttributeID", "Name")
)

In my controller I've tried parameters like attributeId and attribute_attributeId, this is my code:

[HttpPost]
public ActionResult Index(int productId, int attributeId)

(Btw, I'm also receiving the ProductID which is in the query string)

The output of my ddl is ... id="Attribute_AttributeID" name="Attribute.AttributeID" ...

I've tried this also:

@Html.DropDownListFor(
        x => x.Attribute.AttributeID,
        new SelectList(Model.Attributes, "AttributeID", "Name"),
        null,
        new { id = "attributeId", name = "attributeId" }
    )

But then the id just changes and not the both...

So my question is how can I be able to reach the dll without having to write something like x => x.SelectedAttributeID in the ddl.


[HttpPost]
public ActionResult Index(Attribute attribute)
{
   // attribute will have the attributeId property
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜