This is a migrated thread and some comments may be shown as answers.

[Solved] bind SelectedTab to model

0 Answers 37 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Denis
Top achievements
Rank 1
Denis asked on 08 Nov 2010, 06:52 AM
Hi. I create asp.net mvc2 application using Telerik Extensions for ASP.NET MVC.
I have a simple model:
public class SimpleModel
{
   public string MyString { get; set; }
   public int MyInt { get; set; }
   public int SelectedTab { get; set; }
}

Home view with TabStrip:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<TelerikMvcApplication3.Models.SimpleModel>" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<form runat="server">
    <%
        Html.Telerik().TabStrip()
            .Name("TabStrip")
            .Items(items =>
            {
                items.Add().Text("to int")
                     .Content(()=>
                     {%>
                         <p><%:Html.TextBoxFor(m=>m.MyInt) %></p>
                     <%});
                items.Add().Text("to string")
                   .Content(()=>
                               {%>
                                  <p><%:Html.TextBoxFor(m=>m.MyString) %></p>
                               <%});
            })
            .SelectedIndex(Model.SelectedTab)
            .Render();
    %>
    <asp:Button ID="Button1" runat="server" Text="do action" />
</form>
 
</asp:Content>

and home controller with method:
[HttpPost]
public ActionResult Index(SimpleModel model)
{
   switch (model.SelectedTab)
   {
      case 0:
         IntAction(model.MyInt);
         break;
      case 1:
         StringAction(model.MyString);
         break;
   }
   return View(model);
}

I want to bind Selected tab in TabStrip to model field  SelectedTab. How I can do it?
Tags
TabStrip
Asked by
Denis
Top achievements
Rank 1
Share this question
or