I create a subscribe block in my page, include text box and button submit. I have a view name SubMail, this is it's content :
<%# Page Language="C#"
Inherits="System.Web.Mvc.ViewPage<Areas.Admin.Models.SubscribeMail>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server"><title>SubscribeMail</title></head>
<body>
<div style="color:#353535;font-size:small;font-family:Verdana;">
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(true) %>
<div class="editor-label">
Subscribe For Latest Information:
<%: Html.ValidationMessageFor(model => model.Email) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Email, new { #class =
"flathtmlcontrol", name="Email"})%>
<input type="submit" value=" Submit " class="flathtmlcontrol" />
</div>
<% } %>
</div>
</body>
</html>
I used user control to render the content to my web page, This is my user control file :
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<iframe src="<%: Url.Action("SubMail","Portfolio") %>" frameborder="0"
scrolling="no" height="70px"></iframe>
The problem is : when I clicked button submit, after page done, The control text box and submit button disappeared in my page, Until I refresh a page, the control is appear normally in my page.
Can anyone tell me , what problem is it?
The control is in an iframe, when you post the form the control contains it loads the iframe with the results of the action method the form posted to.
Related
I have html code and want to split it between site.master and default.aspx
When I put a full code on site.master it works, but when I took a part of code and put it in default.aspx, it doesn't work!
I just want to know how to make default.aspx reach all classes in .css files
This is my tag which cant take a class from .css
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplicationClinicASP._Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<section class="hero-wrap js-fullheight" style="background-image: url('images/bg_3.jpg');" data-section="home" data-stellar-background-ratio="0.5">
<div class="overlay"></div>
<div class="container">
<div class="row no-gutters slider-text js-fullheight align-items-center justify-content-start" data-scrollax-parent="true">
<div class="col-md-6 pt-5 ftco-animate">
<div class="mt-5">
<span class="subheading">Welcome to Mediplus</span>
<h1 class="mb-4">We are here <br>for your Care</h1>
<p class="mb-4">Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove.</p>
<p>Make an appointment</p>
</div>
</div>
</div>
</div>
</section>
</asp:Content>
I have a page I have been working on, which has some nav tabs on it, which has been working fine until yesterday. When I booted up this am the page no longer shows the tabs. I have closed and reopened VS, I have rebooted my system as well as rebuilding the solution. I've gone through all my code to make sure all tags are closed. I've even gone as far as creating a whole new stand alone page with basic nav tab code and nothing, it doesn't show on the page at all. Any Ideas?
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="Mango.WebForm2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<div class="container">
<ul class="nav nav-tabs" id="myTab">
<li class="active">TabA</li>
<li>TabB</li>
<li>TabC</li>
</ul>
<div class="tab-content">
<div id="TabA" class="tab-pane active">
TAB A
</div>
<div id="TabB" class="tab-pane">
TAB B
</div>
<div id="TabC" class="tab-pane">
TAB C
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#myTab a').click(function (e) {
e.preventDefault()
$(this).tab('show')
});
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
e.relatedTarget // previous tab
});
});
</script>
</asp:Content>
My question will probably sounds dumb to most of you but I have been struggling to find out the problem. I basically have a method and a view (created by right click-> Add View).
This is my method:
public ActionResult yearlyOverview(FormCollection values)
{
return View();
}
And this is my view:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
yearlyOverview
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>yearlyOverview</h2>
</asp:Content>
The error message that I get comes from the browser:
Sys.ArgumentException: Sys.ArgumentException: Cannot deserialize. The data does not correspond to valid JSON. Parameter name: data
This is the master page code:
<%# 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" />
<link href="../../Content/css/fullcalendar.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="page">
<div id="header">
<div id="title">
<h1>PS Administration</h1>
</div>
<div id="logindisplay">
</div>
<div id="menucontainer">
<ul id="menu">
<li><%= Html.ActionLink("Home", "Index", "Home")%></li>
<li><%= Html.ActionLink("Notices", "Index", "Notice")%></li>
<li><%= Html.ActionLink("Job Positions", "Index", "JobPosition")%></li>
</ul>
</div>
</div>
<div id="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
<div id="footer">
</div>
</div>
</div>
</body>
</html>
Has anybody already stumbled on this problem?
Ok my code was good but the mistake i made was to call the form using ajax.beginForm instead of a normal form, and I was trying to parse an object data that wasn't returned by the controller.
I am developing a little MVC app.
The problem: I have a view page which has a form to add events, a form to search for events and a list of events.
It's not a big deal to place the components in single views but I need them in one page. I want a permanent form above the list of events.
The problem is that I don't know what to choice as a model object for the view. If I choice a List of events it's working perfectly with the List but not with the form. If I choice a specific Model Object fitting to the form the list hast problem.
What's the best way to handle such views with forms, lists,... ?
That's my View:
<%# Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="ViewPage<EventPlaza.Web.Models.EventsListViewModel>" %>
<%# Import Namespace="EventPlaza.Storage.Model" %>
<%# Import Namespace="EventPlaza.Web.HtmlHelpers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="EventControlsContainer">
<h3>Add Event Link</h3>
<div>
<% Html.RenderPartial("AddEvent", new AddEventModel()); %>
</div>
<h3>Search for Events</h3>
<div>
<form>
Place:
<input id="elementID" name="elementID" type="text" class="inputSearch" />
Date:
<input id="datepicker" name="elementID2" type="text" class="inputSearch" />
<input id="addEvent" type="submit" value="Find Events" />
</form>
</div>
</div>
<% foreach(var product in Model.Events) { %>
<% Html.RenderPartial("EventSummary", product); %>
<% } %>
<div class="pager">
<%: Html.PageLinks(Model.PagingInfo,
x => Url.Action("List", new {page=x})) %>
</div>
</asp:Content>
This the AddEvent View Control:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<EventPlaza.Storage.Model.AddEventModel>"%>
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("AddEvent", "Event", FormMethod.Post)) { %>
Event Link:
<%: Html.TextBoxFor(x => x.EventLink) %>
Event Name:
<%: Html.TextBoxFor(x => x.EventName) %><br />
Place:
<%: Html.TextBoxFor(x => x.Place) %>
Starting Date:
<%: Html.TextBoxFor(x => x.StartingDate) %> <br />
End Date:
<%: Html.TextBoxFor(x => x.EndDate) %>
<input id="Submit" type="submit" value="Add Event" />
<% } %>
I strongly recommend that you should not be using the Model object from the your Domain Model directly as the type of view instead you should make a custom EventViewModel and keep three different objects corresponding to each partial view you have.
I'm trying to access User.Identity from my master page so I can figure out which user is logged in, however I can't get it to work. If I import System.Security.Principal in my master page it makes no difference:
<%# Import Namespace="System.Security.Principal" %>
I can access it fine if I try within a Controller.
Any idea what I need to do?
What about through HttpContext.Current.User.Identity?
<%=HttpContext.Current.User.Identity.Name %> Will display the current users name
HttpContext.Current.User will get the IPrincipal object.
Here is a master page that only displays the Username in the title:
<%# 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/Style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="page">
<div id="header">
<div id="title">
<h1 id="maintitle">
<%=HttpContext.Current.User.Identity.Name %>
</h1>
</div>
</div>
<div id="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
</div>
</body>
</html>
I think Its Work
HttpContext.Current.User.Identity.Name.ToString()
or
Page.User.Identity.Name.ToString()
You can use HttpContext.Current.User.Name but you need to remember that the Master Page code is executed only after the slave page code. So you can use this variable as long as you are not performing any security logic in the master page.
You can get this from:
Context.User.Identity.Name