Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • yogesh pathak 136 posts 221 karma points
    May 07, 2015 @ 14:18
    yogesh pathak
    0

    Using a strongly typed partial view as Macro , so that i can use it in multiple pages

    I have a situation where i need to create a form which takes user input from text boxes and save it to the database (this form will be used at several places in the website) , so i have created a partial view and then a macro with that partial view , now when i try to put that macro in my grid it says failed to load partial view . what am i lacking into ?

    here is my Model class

       public class TestViewModel
        {
           [Required(ErrorMessage="*")]
           [StringLength(100, ErrorMessage = "Length of last name is not valid")]
           public string LastName { get; set; }

           [Required]
           [Display(Name = "Email Address")]
           [RegularExpression(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$", ErrorMessage = "Enter a valid email address")]
           [StringLength(100, ErrorMessage = "Length of Email Address is not valid")]
           public string Email { get; set; }
        }

     

    and here is my partial view

     

    @using GettingStarted.BLL.ViewModels.TestViewModel


    @{

    Layout=null;

    }

              @using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, new { @class = "form-horizontal" }))
               {

                @Html.TextBoxFor(x => x.LastName, new { @class = "form-control", @placeholder = "Last Name" })

                @Html.ValidationMessageFor(x => x.LastName)       

                @Html.TextBoxFor(x => x.Email, new { @class = "form-control", @placeholder = "Email" })
                @Html.ValidationMessageFor(x => x.Email)
               

    }

     

  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    May 07, 2015 @ 16:25
    Alex Skrypnyk
    0

    Hi Yogesh,

    Is your macro working at another places in the project ?

  • yogesh pathak 136 posts 221 karma points
    May 07, 2015 @ 16:27
    yogesh pathak
    0

    Hey Alex,

    NO , actully making it reuseable is a plan for future.

    Thanks

  • yogesh pathak 136 posts 221 karma points
    May 07, 2015 @ 19:07
    yogesh pathak
    0

    can anyone help me to create a macro by which i can take input from the user and save it to the database?

Please Sign in or register to post replies

Write your reply to:

Draft