c# - MVC EditorFor date doesn't update the sub property in foreach loop -
i'm passing model view , want change user.bannenddate in view , send controller. no matter user.bannenddate actionlink pass value set arrived model. can me ?
[model]
[datatype(datatype.date)] public datetime? bannenddate { get; set; }
[view]
@foreach (var user in model.users) { @html.actionlink("bann", "bannuser", "account", new { userid = user.id, bann = true, bannenddate = user.bannenddate} , null) @html.editorfor(u => user.bannenddate) }
[controller]
public actionresult bannuser(string userid, bool bann, datetime? bannenddate){}
as mike mccaughan stated, values @html.actionlink
static, since they're written when call page.
what do, give actionlink
, editorfor
specific id.
@html.actionlink("bann", "bannuser", "account", new { userid = user.id, bann = true, bannenddate = user.enddate }, new { @id = "targetlink_" + user.id }) @html.editorfor(m => user.bannenddate, null, "bannenddate_" + user.id)
after can listen changes on controls via jquery , change actionlink (userid = 3
result in bannenddate_3
, targetlink_3
):
$('input[id*="bannenddate_"]').change((e) => { var userid = e.target.id.substr(e.target.id.indexof("_") + 1); var link = $("#targetlink_" + userid).attr('href'); $("#targetlink_" + userid).attr('href', link.replace(/(bannenddate=.*$)/g, 'bannenddate=' + encodeuricomponent($("#" + e.target.id).val()))); });
Comments
Post a Comment