jeudi 9 février 2017

how to get approximate values in textarea when I click on an item in the dropdown list items in mvc

how to get approximate data automatically in textarea when I click on an item in the dropdown list items in mvc in the edit action method

model

public partial class Service
{
    public int Id { get; set; }
    public string ItemName { get; set; }
    public string Description { get; set; }
}

view

    <div class="form-group">
        @Html.LabelFor(model => model.ItemName, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10"><p>
            @Html.DropDownListFor(model => model.ItemName, new SelectList(new[] { "Core Banking", "ATM", "RTGS/NEFT", "IFSC Code", "Money Transfer", "Locker Facility", "Mobile Banking (MAMBA)" }), "Select")
            @Html.ValidationMessageFor(model => model.ItemName, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.TextAreaFor(model => model.Description, 8, 100, null)
            @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Update" class="btn btn-default" />
        </div>
    </div>
</div>

}

controller

    public async Task<ActionResult> Edit(int? id)
    {
        if (id == null)
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
        Service service = await db.Services.FindAsync(id);
        if (service == null)
        {
            return HttpNotFound();
        }
        return View(service);

    }

    // POST: Services/Edit/5
    // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
    // more details see http://ift.tt/1eddaz0.
    [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Edit([Bind(Include = "Id,ItemName,Description")] Service service)
    {
        if (ModelState.IsValid)
        {
            db.Entry(service).State = EntityState.Modified;
            await db.SaveChangesAsync();
            return RedirectToAction("Index");
        }
        return View(service);
    }

This is my controller, model, and view page here in the view page when I select an Item from the dropdown list, the corresponding data for the selected item should appear in the textarea just below the drop down list. But this cannot be done for me, Is this possible to do like that? Should I need to change my edit action method? How can I solve my problem ??

Aucun commentaire:

Enregistrer un commentaire