How can I modify the wording of the submit button on the condition within the Homecontroller in mvc?

asp.net-mvc asp.net-mvc-3 entity-framework stored-procedures

Question

I've got an MVC 3 application with one input form on the Index.cshtml page. having a single web grid as welledit ,delete button

I have to modify the wording of my submit button in accordance with these action links. How can I do this inside homecontroller.cs? use a single view for alledit ,insert .

the homecontroller.cs file's useraction

public ActionResult Index(string userAction)
    {
       if (userAction == "Edit" )
        {

        }


        if (userAction == "Delete" )
        {

        }

    }

View code: 
@model Mapping.Models.SecurityIdentifierMappingViewModel
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Mapping</legend>
        <div class="editor-label">
            @Html.Label("Pricing SecurityID")
        </div>
        <div class="editor-field">
            @Html.HiddenFor(model => model.MappingControls.Id)
            @Html.DropDownListFor(model => model.MappingControls.PricingSecurityID,
         new SelectList(Model.PricingSecurities, "Value", "Text"),
         "Select SecurityID"
            )
            @Html.ValidationMessageFor(model => model.MappingControls.PricingSecurityID)
        </div>
        <div class="editor-label">
            @Html.Label("CUSIP ID")
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.MappingControls.CUSIP,
         new SelectList(Model.CUSIPs, "Value", "Text"),
            "Select CUSIP"
            )
            @Html.ValidationMessageFor(model => model.MappingControls.CUSIP)
        </div>

        <div class="editor-label">
            @Html.Label("Calculation")
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.MappingControls.Calculation)
            @Html.ValidationMessageFor(model => model.MappingControls.Calculation)
        </div>
        <p>
            <input type="submit" value="Insert" />
        </p>
    </fieldset>
}

on same page i have a webgrid I need to change text of submit button to Update when I clicked on webgrid's edit button. i'm newbie.

Webgrid code
    @model IEnumerable<Mapping.Models.SecurityIdentifierMapping>
    @{
        ViewBag.Title = "Mapping";
        WebGrid grid = null;
        if (Model.Count() > 0)
        {
            grid = new WebGrid(source: Model,
                                    defaultSort: "Id",
                                    canPage: true,
                                    canSort: true,
                                    rowsPerPage: 10);
        }
    }
    <h3>
        Mapping Web Grid</h3>
    @if (grid != null)
    {
        @grid.GetHtml(
                    tableStyle: "grid",
                    headerStyle: "head",
                    alternatingRowStyle: "alt",
                    columns: grid.Columns(
                                                grid.Column("", header: null, format: @<text>@Html.ActionLink("Edit", "Index", new { uid = (int)item.id, userAction = "Edit" })
        @Html.ActionLink("Delete", "Index", new { uid = (int)item.id, userAction="Delete" }, new { @class = "Delete" })</text>),
                                                grid.Column("PricingSecurityID"),
                                                grid.Column("CUSIP"),
                                                grid.Column("Calculation")
                                              )

                    )
    }
1
1
7/29/2013 4:10:28 PM

Accepted Answer

enter code here A ViewBag property should be set in the controller:

public ActionResult
Index(string userAction) 
    { 
       if (userAction == "Edit"
) 
        {
   ViewBag.SubmitValue = "Edit";
        } 

        if (userAction == "Delete" ) 
        {
 ViewBag.SubmitValue = "Delete";
        } 
    }

..after which the value will be shown in the view:

<input type="submit" value="@ViewBag.SubmitValue" />
5
4/23/2012 3:36:40 PM

Popular Answer

The label text might be added as a property in the ViewBag in the Controller, which is a quick fix, but it's not always the best course of action.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow