Wednesday, 15 September 2010

c# - How to save an input value in ASP.NET with razor? -



c# - How to save an input value in ASP.NET with razor? -

i have code on view :

<div class="editor-label"> @html.label("periode de validation") </div> <div class="editor-field"> mois: <input data-val="true" data-val-number="the field part1_mois must number." id="part1_mois" name="part1_mois" style="width: 80px" type="text" value="" /> ans : <input data-val="true" data-val-number="the field part1_ans must number." id="part1_ans" name="part1_ans" style="width: 80px" type="text" value="" /> total en mois : <input data-val="true" data-val-number="the field part1_fperiodevalid must number." id="part1_fperiodevalid" name="part1_fperiodevalid" style="width: 80px" type="text" value="" /> @html.validationmessagefor(model => model.fperiodevalid) </div>

i want convert period in year + month in month, have script :

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script>jquery(function ($) { $(":text[id*=_mois],:text[id*=_ans]").blur(function () { var mois = $(":text[id*=_mois]").val(); var ans = $(":text[id*=_ans]").val(); var total = mois / 1 + ans * 12; $(":text[id*=fperiodevalid]").val(total); }); });</script>

but don't know how save result (input button periodevalid) on database ...

i have tried :

total en mois :

<input data-val="true" data-val-number="the field part1_fperiodevalid must number." id="part1_fperiodevalid" name="part1_fperiodevalid" style="width: 80px" type="text" value="@model.fperiodevalide" />

my model : public int? fperiodevalid { get; set; }

mvc modelbinder utilize input name create action model. if have model like:

public class mymodel { public int? fperiodevalid { get; set; } }

you must alter part1_fperiodevalid fperiodevalid

<input id="part1_fperiodevalid" name="fperiodevalid" ... /> or @html.editorfor(model => model.fperiodevalid)

and action this

public actionresult create(mymodel model){ }

c# asp.net ajax asp.net-mvc razor

No comments:

Post a Comment