this is the master page :
<%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="header1" runat="server" />
</head>
<body>
<div class="page">
<div id="header">
<div id="title">
<h1>My MVC Application</h1>
</div>
<div id="logindisplay">
<% Html.RenderPartial("LogOnUserControl"); %>
</div>
<div id="menucontainer">
<ul id="menu">
<li><%= Html.ActionLink("Home", "Index", "Home")%></li>
<li><%= Html.ActionLink("About", "About", "Home")%></li>
<li><%= Html.ActionLink("Imoveis", "Index", "Categoria")%></li>
<li><%= Html.ActionLink("Admin", "Index", "Admin")%></li>
<li><%= Html.ActionLink("User", "Index", "User")%></li>
</ul>
</div>
</div>
<div id="left">
<% Html.RenderPartial("~/Views/Imovel/Pesquisa.ascx"); %>
</div>
<div id="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
<div id="footer">
</div>
</div>
</div>
</body>
</html>
Partial View
<%= Html.DropDownList("categoria_id", (SelectList)ViewData["Categoriass"], "--Selecciona um--")%>
<div class="editor-label">
<%= Html.LabelFor(model => model.categoria_id) %>
</div>
<div class="editor-field">
<%= Html.DropDownListFor(model => model.categoria_id, (SelectList)ViewData["Categorias"], "--Selecciona um--")%>
<%= Html.ValidationMessageFor(model => model.categoria_id) %>
</div>
This is the problem:
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
**ViewData["Categoriass"] = new SelectList(catRepository.FindAllCategorias().AsEnumerable(), "id", "nome", 3);**
return View();
}
Since the partial view is in the master page, how do I get its model?
I think you should create an ActionFilter and apply it on your controllers.
Create an action filter like this
public class DataForMasterPageAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
//initiate your repository
var catRepository = ...;
//then create the viewdata like so
filterContext.Controller.ViewData["Categorias"] = new SelectList(catRepository.FindAllCategorias().AsEnumerable(), "id", "nome", 3);
}
}
Then apply it on the controller and it will be available for all actions as well. Like so;
[DataForMasterPage]
public class CategoriaController : Controller
{
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View();
}
}
On the partial view you just call the ViewData as usual, no need to change anything
<div class="editor-label">
<%= Html.LabelFor(model => model.categoria_id) %>
</div>
<div class="editor-field">
<%= Html.DropDownListFor(model => model.categoria_id, (SelectList)ViewData["Categorias"], "--Selecciona um--")%>
<%= Html.ValidationMessageFor(model => model.categoria_id) %>
</div>
Might have performance issues, but its one of the simplest ways to avoid setting the ViewData on every method.
You can create base class for your controllers and set it during creation if you need to query for it with every request:
public class BaseController : Controller
{
public BaseController()
{
var catRepository = ...;
ViewData["Categoriass"] = new SelectList(catRepository.FindAllCategorias().AsEnumerable(), "id", "nome", 3);
}
}
That is not really efficient,because it will be executed with every controller. You can also create action filter which sets ViewData and apply it where needed.
I have try Nick Masao & LukLed solutions, both of them are works.
However, the viewdata is set for masterpage, in my case, i assume masterpage will render every page.
I have to
apply the [DataForMasterPage] attribute (Nick Masao's solutions) or
or
inherits the BaseController (LukLed's solutions)
on every View's Controller.
So, is it possible create a Class and invoke on Global.asax Application_Start event to make it Set viewdata everytimes?
You could also create a ContentPlaceHolder where you want the partial view to render and call the RenderPartial() from the underlying pages. That way you can pass the model as usual.
Related
I want to ask about dynamic menu based on role in master page asp.net mvc 4. before i ask about it. I have database menu in sql server express 2008 like this:
Id_Menu int NotNull
Displaymenu varchar(50) Null
Url varchar(50) Null
ParentID int Not Null
and i have created master page in mvc 4 like this :
<body>
<header>
<div class="float-left">
<img src="../../Images/logo.png" width="350" height="95" />
</div>
<div class="content-wrapper">
<div class="float-right">
<section id="login">
<%: Html.Partial("_LoginPartial") %>
</section>
<nav>
<ul id="menu">
<li><%: Html.ActionLink("Home", "Index", "Home") %></li>
<li><%: Html.ActionLink("About", "About", "Home") %></li>
<li><%: Html.ActionLink("Contact", "Contact", "Home") %></li>
</ul>
</nav>
</div>
</div>
</header>
<div id="body">
<asp:ContentPlaceHolder ID="FeaturedContent" runat="server" />
<section class="content-wrapper main-content clear-fix">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</section>
</div>
<footer>
<div class="content-wrapper">
<div class="float-left">
<p>© <%: DateTime.Now.Year %> - Cenie.Sistem Informasi.IT
Telkom</p>
</div>
</div>
</footer>
and the i have created nested master page like this :
<%# Master Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
AutoEventWireup="true" CodeBehind="Dashboard.master.cs"
Inherits="TA_SID.Views.Shared.Dashboard<TA_SID.Models>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<div class="span3 main-menu-span">
<div class="well nav-collapse sidebar-nav">
<ul class="nav nav-tabs nav-stacked main-menu">
<li class="nav-header hidden-tablet">MAIN
MENU</li>
if()
<li><a class="ajax-link"
href="/Admin/Index"><i class="icon-home"></i><span class="hidden-tablet">
Dashboard</span>
</a></li>
<li><a class="ajax-link"
href="/Admin/PertaminaIndex"><i class="icon-eye-open"></i><span class="hidden-tablet">
Pertamina</span></a></li>
<li><a class="ajax-link"
href="/Admin/DistributorIndex"><i class="icon-edit"></i><span class="hidden-tablet">
Distributor</span></a></li>
<li><a class="ajax-link"
href="/Admin/CustomerIndex"><i class="icon-list-alt"></i><span class="hidden-tablet">
Customer</span></a></li>
<li><a class="ajax-link"
href="/Admin/ProdukIndex"><i class="icon-font"></i><span class="hidden-tablet">
Product</span></a></li>
<li><a class="ajax-link" href="table.html">
<i class="icon-align-justify"></i><span class="hidden-tablet"> Chart</span></a></li>
<li><a class="ajax-link"
href="calendar.html"><i class="icon-calendar"></i><span class="hidden-tablet">
Calendar</span></a></li>
<li><a class="ajax-link" href="grid.html"><i
class="icon-th"></i><span class="hidden-tablet"> User</span></a></li>
</ul>
</div><!--/.well -->
</div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptsSection" runat="server">
</asp:Content>
can you help me.. How to create dynamic menu load in nested master page if i log in as admin or as user after i success log in as role?
thank you for your help..
First of all, you don't want to do this logic in a master page. You want to create a partial view that will build the menu based on the model information returned by a child action in some controller. For example:
You should move this logic into some controller that is in charge of building navigation. Inside of this controller you should declare a child action that returns the information that you need.
If you plan to store URL and Description in a database, you might as well store access privileges in a table as well. That way you can pass user's group or user name and retrieve a collection of URL to which that user has access. After that you could use a code similar to the one below.
For example:
public class NavigationController : Controller
{
[ChildActionOnly]
public PartialViewResult GetMenuForUser()
{
var model = _securityLayer.GetUrlForUser(HttpContext.User.Identity.Name);
return PartialView("_UserMenu", model);
}
}
Your _UserMenu.cshtml could be like:
#model IEnumerable<SomeCollection>
#foreach(var url in Model) {
<li><a class="ajax-link" href="#url.Url">#url.Description</a></li>
}
THen in your master page, where you want to use the menu you would call:
<div class="well nav-collapse sidebar-nav">
<ul class="nav nav-tabs nav-stacked main-menu">
<li class="nav-header hidden-tablet">MAIN MENU</li>
#{ Html.RenderAction("GetMenuForUser", "Navigation"); }
</ul>
</div>
This should give you an idea how to proceed regardless of whether you store user access rights in a database.
UPDATE: Sorry, I realized later that you are using ASPX View Engine and not Razor. You will need to convert to ASPX View Engine my markup.
Try creating a controller where you use identity to get an IList of the current user's roles then convert that list into a string separated with commas then store that in a viewbag or in tempdata depending on your preference then in your layout use the Viewbag data to display items basing on what role is found in there. This is the controller
[Authorize]
public ActionResult Index()
{
if (User.Identity.IsAuthenticated)
{
var user = User.Identity;
ViewBag.Name = user.Name;
ViewBag.DisplayMenu = UserRole();
return View();
}
else
{
ViewBag.Name = "Not Logged in";
}
return View();
}
public string UserRole()
{
string urole = "non";
if (User.Identity.IsAuthenticated)
{
var user = User.Identity;
ApplicationDbContext context = new ApplicationDbContext();
var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
var s = UserManager.GetRoles(user.GetUserId());
urole = String.Join(",", s.ToArray());
}
return urole;
}
What i am trying to do is create a SubCategory object. In order to do so i have made a viewmodel that will supply my view with the nescesarry data (including a category object that the subcategory will be bound to.)
when i post my form the viewmodel is returned to my controller but all the properties of my subcategory and my selected value from a dropdownlist is null.
what am i doing wrong? :S
view:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.master" Inherits="System.Web.Mvc.ViewPage<SkyLearn.Areas.Categories.Models.CategoryViewModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Create
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Create</h2>
<script src="<%: Url.Content("~/Scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js") %>" type="text/javascript"></script>
<form action="" method="post" enctype="multipart/form-data">
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>SubCategory</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.subcategory.Title) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.subcategory.Title)%>
<%: Html.ValidationMessageFor(model => model.subcategory.Title)%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.subcategory.Icon)%>
</div>
<div class="editor-field">
<input type="file" name="icon" id="icon"/>
</div>
<%: Html.DropDownListFor(selectedcategory => Model.selectedCategory, Model.categories) %>
<div class="editor-label">
<%: Html.LabelFor(model => model.subcategory.Description)%>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.subcategory.Description)%>
<%: Html.ValidationMessageFor(model => model.subcategory.Description)%>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
</form>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="SideContent" runat="server">
</asp:Content>
Controller:
[Authorize(Roles = "administrator")]
[HttpPost]
public ActionResult Create(CategoryViewModel viewmodel, HttpPostedFileBase Icon)
{
SubCategory subcategory = viewmodel.subcategory;
subcategory.Category = categorycontroller.getCategoryByName(viewmodel.selectedCategory);
if (Icon != null && Icon.ContentLength > 0)
{
// extract only the filename
var fileName = Path.GetFileName(Icon.FileName);
// store the file inside ~/App_Data/uploads folder
var path = Path.Combine(Server.MapPath("../../Content/icons/"), fileName);
Icon.SaveAs(path);
subcategory.Icon = fileName;
}
if (ModelState.IsValid)
{
db.subcategories.Add(subcategory);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(subcategory);
}
ViewModel:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Web.Mvc;
namespace SkyLearn.Areas.Categories.Models
{
public class CategoryViewModel
{
public List<SelectListItem> categories;
public SubCategory subcategory;
public string selectedCategory;
public CategoryViewModel()
{
categories = new List<SelectListItem>();
subcategory = new SubCategory();
selectedCategory = "";
}
}
}
the viewmodel contains a list of categories that the subcategory im trying to create can be bound to. it also contains a subcategory object i can use to create the subcategory from. and the last property is a string i want to use for binding the choice in the dropdownlist.
ASP.Net MVC3's SelectListItem doesn't behave how you'd expect. Also, try Html.DropDownListFor() rather than Html.EditorFor() to make your dropdown list.
In the ViewModel:
public IList<string> PossibleValues {get; set;}
public string SelectedValue {get; set;}
Load the values into PossibleValues in your ViewModel's constructor.
In the View:
#Html.DropDownListFor(x => x.SelectedValue, new SelectList(Model.PossibleValues))
This will autogenerate your dropdown list and bind it to your model. You can pass default values and other customizations into this Html helper function too, if you want.
Saving Other Values
You can save other values, values which the user shouldn't have the option to edit but which aren't mission-critical if the user does edit, with
#Html.HiddenFor(m => m.RememberThisValue);
Remember, this value is hidden from display but can still be edited on the DOM and posted with whatever the user wants. Make sure you protect yourself from malicious value injection by checking POST'd hidden values.
Store everything important on the server-side, pass a hash/private key in to the user through your model, and implement a static session dictionary to store these small bits of information.
I have a website in Asp.Net that I am trying to port to MVC 3 and I have only worked with MVC 2 before. I stumbled across the following asp function
<div class="popup-holder">
<ul class="popups">
<asp:Repeater runat="server" ID="ourTeamRepeater" OnItemDataBound="ourTeamRepeater_ItemDataBound">
<ItemTemplate>
<asp:Panel ID="pnlTeamMember" runat="server">
<li id="TeamMember" runat="server" class="memberImage">
<asp:Image runat="server" ID="memberImg" />
</li>
<div class="popup">
<div class="img-holder">
<asp:Image runat="server" ID="memberImgBig" />
</div>
<div class="popup-text-t">
<div class="close">
close
</div>
</div>
<div class="popup-text">
</div>
<div class="popup-text-b">
</div>
<div class="holder">
<asp:Literal ID="memberDescription" runat="server" />
</div>
</div>
</asp:Panel>
</ItemTemplate>
</asp:Repeater>
</ul>
it looks like maybe this works similarly to a for loop, but I'm not quite positive how to convert it to MVC 3 architecture.
Porting an existing WebForms application to ASP.NET MVC is not only about blindly translating line by line some WebForms view code that you have. You should take into account the semantics of the target platform. For example converting this asp:Repeater into an ugly foreach loop instead of taking into account things like view models, display templates would not be very good.
So in ASP.NET MVC you start by designing view models:
public class MemberViewModel
{
public int Id { get; set; }
public string Description { get; set; }
}
then you design a controller action which populates this view model:
public ActionResult Index()
{
IEnumerable<MemberViewModel> model = ...
return View(model);
}
then you write a strongly typed view in which you invoke a display template:
#model IEnumerable<MemberViewModel>
#Html.DisplayForModel()
and then you define a display template which will be rendered for each element of the collection (~/Views/Shared/DisplayTemplates/MemberViewModel.cshtml):
#model MemberViewModel
<li id="TeamMember" class="memberImage">
<img src="Url.Action("ThumbnailImage", new { id = Model.Id })" alt=""/>
</li>
<div class="popup">
<div class="img-holder">
<img src="Url.Action("FullImage", new { id = Model.Id })" alt=""/>
</div>
<div class="popup-text-t">
<div class="close">
close
</div>
</div>
<div class="popup-text"></div>
<div class="popup-text-b"></div>
<div class="holder">
#Html.DisplayFor(x => x.Description)
</div>
</div>
Now you will notice the two additional ThumbnailImage and FullImage controller actions that will allows us to fetch the images of the members given the member id. For example:
public ActionResult ThumbnailImage(int id)
{
byte[] thumbnail = ...
return File(thumbnail, "image/jpeg");
}
Now that's more like ASP.NET MVC. As you can see it's a totally different pattern than classic WebForms.
You're quite right to suppose that the MVC equivalent of an asp:Repeater is
<% foreach( var item in Model )
{ %>
<!-- Your HTML Markup -->
<% } %>
You're right about it being similar to a for loop. A simple implementation might look like this:
<div class="popup-holder">
<ul class="popups">
<%foreach(var item in Model.Items) { %>
<div id="pnlTeamMember">
<img src="<%: item.MemberImageSrc %>" ID="memberImg" />
<div class="popup">
<div class="img-holder">
<img src="<%: item.MemberImgBigSrc %>" ID="memberImgBig" />
</div>
<div class="popup-text-t">
<div class="close">
close
</div>
</div>
<div class="popup-text">
</div>
<div class="popup-text-b">
</div>
<div class="holder">
<%: item.MemberDescription %>
</div>
</div>
</div>
<% } %>
</ul>
You'll notice that there are no longer any controls with runat="server", nor are there any events linked to handlers in the code-behind. Instead, we are assuming that the controller has populated the Model object with objects representing the data that we need to display. That is the role of the controller when using MVC.
A repeater is just a loop that provides databinding so that you can access the items in the collection that you are looping. If you look in the ourTeamRepeater_ItemDataBound method you will find the code that uses the databound items to populate the elements in the item template with data.
Usually you can just use a foreach loop in MVC to loop the items. Example:
<% foreach (var item in items) { %>
<div class="holder">
<%= item.Description %>
</div>
<% } %>
<%# Page Language="C#" MasterPageFile="~/Views/Shared/MasterPage.Master" Inherits="System.Web.Mvc.ViewPage<EAZYITT_LOGIN.Models.CombinedViewModel>" %>
<asp:Content ContentPlaceHolderID="TitleContent" runat="server">
LoginPage
</asp:Content>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
<div id="LoginWindow">
<% Html.RenderPartial("LoginWindow", ViewData.Model.Logon); %>
<a id="ForgetPassword" href="#" onclick="loadSegment()">Forgot Password</a>
</div>
<div id="PassReminderWindow">
<% Html.RenderPartial("ReminderWindow", ViewData.Model.Reminder); %>
</div>
</asp:Content>
Each partial view is strongly typed with separate postbacks to the server
Login:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<EAZYITT_LOGIN.Models.LogOnModel>" %>
<div id="loginPage">
<h2>Login Page</h2>
<h3>Submit your credentials to continue or register</h3>
<%: Html.ActionLink("New Registration", "Register")%>
<%: Html.ValidationSummary(true)%>
<%: Html.ValidationSummary()%>
<div class="validation-summary-errors">
<span id="loginError"></span>
</div>
<% using (Html.BeginForm("LoginWindow","Account",FormMethod.Post)) { %>
<%:Html.LabelFor(m =>m.EmailAddress) %>
<%:Html.ValidationMessageFor(m => m.EmailAddress) %>
<%:Html.TextBoxFor(m => m.EmailAddress) %>
<%:Html.LabelFor(m =>m.Password) %>
<%:Html.ValidationMessageFor(m => m.Password) %>
<%:Html.PasswordFor(m => m.Password)%>
<%:Html.CheckBoxFor(m => m.RememberMe)%>
<%:Html.LabelFor(m => m.RememberMe)%>
<p>
<input type="submit" value="Log On" />
</p>
<% } %>
</div>
Password Reminder:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<EAZYITT_LOGIN.Models.ReminderModel>"%>
<div id="PasswordReminderDiv">
<h2>PasswordReminder</h2>
<%: Html.ValidationSummary(true) %>
<div class="validation-summary-errors"><span
id="reminderError"></span></div>
<% using (Html.BeginForm("PasswordReminder",
"Account",FormMethod.Post))
{ //'8' o-o +:: %>
<%:Html.LabelFor(m=>m.ReminderEmailAddress) %>
<%:Html.ValidationMessageFor(m =>
m.ReminderEmailAddress)%>
<%:Html.TextBoxFor(m => m.ReminderEmailAddress) %>
<p>
<input type="submit" value="Send Reminder" />
</p>
<%} %>
</div>
The results are submitted to their separate methods in the controller:
[HttpGet]
public ActionResult Login()
{
CombinedViewModel cModel = new CombinedViewModel();
cModel.Logon = new LogOnModel();
cModel.Reminder = new ReminderModel();
return View(cModel);
}
[HttpPost]
public ActionResult Login(CombinedViewModel _login)
{
return View(_login);
}
[HttpGet]
public ActionResult LoginWindow()
{
return PartialView();
}
[HttpPost]
public ActionResult LoginWindow(LogOnModel _login)
{
if (ModelState.IsValid)
{
if (LoginService.ValidateUser(siteId, _login.EmailAddress, _login.Password))
{
//Goto Next Page
ModelState.AddModelError("loginError", "LOGIN - OK");
}
else
{
//Failed Login
ModelState.AddModelError("loginError", "Wrong username or password");
}
}
return PartialView("LoginWindow", _login);
}
[HttpGet]
public ActionResult PasswordReminder()
{
return View();
}
[HttpPost]
public ActionResult PasswordReminder(ReminderModel _reminder)
{
TempData["ModelState"] = ModelState;
if (LoginService.ValidateNewUser(siteId, _reminder.ReminderEmailAddress))
ModelState.AddModelError("reminderError", "The E-mail address does not exist");
if (ModelState.IsValid)
{
ModelState.AddModelError("reminderError", "E-mail found, send e-mail to user");
}
return PartialView("PasswordReminder",_reminder);
}
Ideally, I would like the main view (Login.aspx) to be displayed regardless of the validation.
However, I've currently got the validation on each partial view working, BUT it is taking me to their separate partial views on failed validation as opposed to the main view.
How would I get it to update the partial view only? Is this the way to do it or should I be using AJAX?
The only way to update the partial view only is AJAX, use AJAX.BeginForm or use JQuery. Otherwise, it expects to go through the full lifecycle.
HTH.
I'm not sure exactly what I'm doing wrong here.
I have an action which returns a partial view:
public class SharedController : BaseController
{
public ActionResult StudentPoll()
{
WAM.X2O.FuelUpToPlayContext db = new WAM.X2O.FuelUpToPlayContext(WAM.Utilities.Config.ConnectionString);
WAM.X2O.StudentPoll m = (from s in db.StudentPolls where s.IsActive == true select s).SingleOrDefault();
return PartialView("StudentPoll", m);
}
}
I implement the action like this:
<%Html.RenderAction("StudentPoll", "Shared");%>
The partial view looks like this:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl< Fuel_Up_To_Play.Models.Shared.StudentPollModel >" %>
<%if(ViewData.Model != null){ %>
<div class="block">
<div class="holder">
<div class="frame">
<h2 class="poll">Student Poll</h2>
<!-- TODO - Student Poll has a form screen, and results screen.
Results anim is here to demo what should happen after submision -->
<form action="/Shared/SubmitStudentPoll" method="post" class="poll-form" <%if(ViewData.Model.StartingState == Fuel_Up_To_Play.Models.Shared.StudentPollModel.PollStates.RESULTS){%>style="display:none"<%} %>>
<fieldset>
<span><%=ViewData.Model.StudentPoll.Question %></span>
<input type="hidden" id="student_poll" name="student_poll" value="<%=ViewData.Model.StudentPoll.ID %>" />
<%foreach(WAM.X2O.StudentPollAnswer answer in ViewData.Model.StudentPoll.RelatedStudentPollAnswers){ %>
<div class="row">
<input type="radio" class="radio" id="answer_<%=answer.ID %>" name="poll_answer" value="<%=answer.ID %>"/>
<label for="answer_<%=answer.ID %>"><%=answer.AnswerText%></label>
</div>
<%} %>
<input id="submitBtn" type="image" style="display:none" class="image" src="/Content/images/btn-submit-05.gif" />
</fieldset>
</form>
<div class="progress-box" <%if(ViewData.Model.StartingState == Fuel_Up_To_Play.Models.Shared.StudentPollModel.PollStates.FORM){%>style="display:none"<%} %>>
<span><%=ViewData.Model.StudentPoll.Question %></span>
<%int answerCounter = 0;
foreach(WAM.X2O.StudentPollAnswer answer in ViewData.Model.StudentPoll.RelatedStudentPollAnswers){ %>
<div class="box">
<span class="names"><%=answer.AnswerText%><strong class="quesPctTxt" rel="<%=ViewData.Model.AnswerPercentages[answerCounter] %>"></strong></span>
<div class="progress-bar"><span class="quesPctBar"></span></div>
</div>
<%
answerCounter++;
} %>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="/Scripts/studentpollscript.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("input.radio[name='poll_answer']").change(function() {
$("#submitBtn").show();
});
$("#submitBtn").click(function() {
$(".poll-form").ajaxForm(
{ dataType: 'json',
success: function(json) {
alert(json.Success);
}
}
);
});
});
</script>
<%} %>
Natually, I would expect this approach to return HTML. But no. Instead it appears that binary is being rendered in the browser. Obviously I'm doing something wrong but I don't know what.
Here's what is rendered in the browser:
http://screencast.com/t/Mjg1OWJj
Any ideas folks? I'm stumped but I'm sure it's something simple that I'm missing.
I would guess that it simply isn't setting the content type correctly. What does a network trace (fiddler, etc) show? Perhaps try using View("StudentPoll", m); instead of PartialView(...)?
Also; be careful - many of those <%= look unsafe, i.e. not html-encoded.