开发者

Populating and passing complex object from MVC2 view to controller action

I have following code in my MVC2 view:

<tr class="edit" style="display:none">
    <td>
        <%= Html.DropDownList("drpFields", new SelectList(Model.Fields, "FieldID", "NiceName", whiteout.FieldID)) %>      
    </td>
    <td>
        <%= Html.DropDownList("drpStartTimeh", new SelectList(Model.Hours, whiteout.StartHour.Hour.ToString("0,0")))%>
        <%= Html.DropDownList("drpStartTimem", new SelectList(Model.Minutes, whiteout.StartHour.Minute.ToString("0,0")))%>
        <%= Html.DropDownList("drpStartTimet", new SelectList(Model.AMPM, whiteout.StartHour.Hour > 12 ? "PM" : "AM"))%>
        -
        <%= Html.DropDownList("drpEndTime", new SelectList(Model.Hours, whiteout.EndHour.Hour > 12 ? (whiteout.EndHour.Hour - 12).ToString("0,0") : whiteout.EndHour.Hour.ToString("0,0")))%>
        <%= Html.DropDownList("drpEndTimem", new SelectList(Model.Minutes, whiteout.EndHour.Minute.ToString("0,0")))%>
        <%= Html.DropDownList("drpEndTimet", new SelectList(Model.AMPM, whiteout.EndHour.Hour > 12 ? "PM" : "AM"))%>
    </td>
    <td>
      <%= Html.DropDownList("drprepeat", new SelectList(Model.RepeatList,whiteout.Repeats))%>
    </td>
    <td>
     Active
    </td>
    <td>            
             <a class="icon-button-cancel" href='<%: Url.Action("EditWhiteOut", "Settings", new {Id = whiteout.WhiteoutID}) %>'>
    <img src='<开发者_StackOverflow社区%: Url.Content("~/static/Images/expanded.png") %>' alt="Delete this device" />
</a>
            <a class="icon-button-success" href="#">
            <img src="/static/images/gear.png" alt="Edit this device" /></a>
    </td>
    <td>    
    </td>
</tr>

I want to create an object of type Whiteout class and populate it with values selected by user from dropdowns and send to settingcontroller's EditWhiteout action method instead of passing only new {Id = whiteout.WhiteoutID}. How can I do this ?

Please suggest solution.

Thanks.


Frist of all the link will result in a Get instead of Post. You need to use javascript function attached to the hyperlink to perform a POST to the action on the controller.

<a class="icon-button-cancel" onclick="return SomeFunction(this)" href='<%: Url.Action("EditWhiteOut", "Settings", new {Id = whiteout.WhiteoutID}) %>'>

function SomeFunction(obj)
{

 document.forms[0].action = obj.href;
 document.forms[0].submit();
 return false;
}

please also store the whiteout.whiteoutID in a hidden field.

 ActionResult EditWhiteout (Whiteout whiteout)

{ Your Code goes here. }

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜