well I have four departments in my dropdownlist, I want it to be like, when I select the required item in the dropdownlist it should open the registration form of that department.

    <div class="form-group string department">
        <label class="control-label col-md-3>
          Select Department
        </label>
   <div class="col-md-4">
        @{
            List<SelectListItem> deplist = new List<SelectListItem>();
            deplist.Add(new SelectListItem { Value = "1", Text = "Department A" });
            deplist.Add(new SelectListItem { Value = "2", Text = "Department B" });
            deplist.Add(new SelectListItem { Value = "3", Text = "Department C" });
            deplist.Add(new SelectListItem { Value = "4", Text = "Department D" });
          }
           @Html.DropDownListFor(m => m.Department, deplist, "--Select Department -", new { @class = "form-control" })
    </div>

my views are like this DOP department

<div class="panel-body">
    <div class="form-group string required patient_regno">
        <label class="control-label col-md-2">
        Regestration No
        </label>
    <div class="col-md-3">
         @Html.TextBoxFor(m => m.RegistrationNo, new { placeholder = "BX1234", @class = "string required form-control" })
         @Html.ValidationMessageFor(m => m.RegistrationNo, null, new { @class = "text-error" })
    </div>
    <div class="form-group string required patient_regdate">
    <label class="control-label col-sm-2">
     Date</label>
    <div class="col-md-3">
         @Html.TextBoxFor(m => m.RegistrationDate, new{@class="string required form-control", type="date"})
         @Html.ValidationMessageFor(m => m.RegistrationDate, null, new { @class = "text-error" })</div>
    </div>
    </div>

other department is DOT

<div class="panel-body">
        <div class="form-group string patient_onsetdate">
            <label class="control-label col-md-2">
            Onset Date
            </label>
        <div class="col-md-3">
             @Html.TextBoxFor(m => m.OnsetDate, new { @class = "string form-control", type = "date", size = "50" })
        </div>
        <div class="form-group patient_onset">
        <label class="control-label col-sm-2">
         Onset Place</label>
        <div class="col-md-3">
            @Html.TextBoxFor(m => m.OnsetAt, new { @class = "string form-control", placeholder = "Place", type = "text" })
        </div>
        </div>

I have created views for different departments how can I open them as a form on the current view when I select an item from DropDownList?

This question already has an answer here:

Let's say I have this CSS embedded in my Index.cshtml:

.spinning {
    animation: spin 1s infinite linear;
    -webkit-animation: spin2 1s infinite linear;
}

@keyframes spin {
    from { transform: scale(1) rotate(0deg); }
    to { transform: scale(1) rotate(360deg); }
}

@-webkit-keyframes spin2 {
    from { -webkit-transform: rotate(0deg); }
    to { -webkit-transform: rotate(360deg); }
}

The above will not compile because @ will be considered a Razor directive to execute C# code.

How can I tell the Razor engine to omit these @?

I have my profile model with these properties

public string FullName {get; set;}
public string Email {get; set;}

And I'd like the text to be displayed like this:

John P Doe (someemail@notreal.com)

Currently I do this:

<div class="row section-head-bold">
    @Html.DisplayFor(modelItem => item.Profile.FullName)
    @Html.Raw(" (")@Html.DisplayFor(modelItem => item.Profile.Email)@Html.Raw(")")
</div>

Is there a better/cleaner way?

I am dynamically adding a div inside another div and I am successful in doing it. However, I want to display data inside the dynamically added div in which I am really stuck. Below is the code:

.js

function GetInfoOnSameActivity(currentElem, priorityObj) {    
        if (priorityObj.UpcomingActivities() != undefined) {
            $.each(priorityObj.UpcomingActivities(), function (i, v) {
            var activityElements = $(currentElem).find('.priority-icon')[i];
            var div = $('<div>').addClass('detail-popup');                
            $(activityElements).append(div);           
                });
    }
  }

This above jquery function is called at the load time. The cshtml is as below:

.cshtml

<div class="priority-icon">                    
                @*<div class="detail-popup">
                    <strong data-bind="text:Title()"></strong>
                    <p data-bind="text:Description()">
                    </p>
                </div>*@
            </div>

The code that I have commented in the .cshtml, is the class that I am adding dynamically. I now want to add the tag values dynamically inside the class detail-popup. Do I need to add and append each tag that I have used in the .cshtml inside the dynamically added div to show their value(eg. <strong>, <p>)

I'm trying to build a log collector which receives multiple JSON documents in a HTTP from our CDN. The POST comes through with a content type of application/x-www-form-urlencoded, and the payload contatins anywhere up to 1000 documents in the following format:

{JSON record1}
{JSON record2}
{JSON record3} 

I have written the following piece of code, which get's the payload from the POST request, but i need to find a way of iterating through each document so that i can handle them individually (store in Azure table storage as an example).

if(IsPost){
    string contentType = Request.ContentType;

    var name = DateTime.Now.Ticks.ToString();

    StreamReader stream = new StreamReader(Request.InputStream);
    string x = stream.ReadToEnd();
    string contentBody = HttpUtility.UrlDecode(x);

    dynamic jsonObj = JsonConvert.DeserializeObject(contentBody);

    foreach (var obj in jsonObj)
    {
        var singledataFile = Server.MapPath("~/output/gavin" + name + ".json");
        var singleObj = JsonConvert.SerializeObject(obj);
        File.WriteAllText(@singledataFile, singleObj);
    }

    string output = contentType + contentBody;



    var datafile = Server.MapPath("~/output/" + name + ".json");
    File.WriteAllText(@datafile, output);
}

However, the above code results in a 500 error, with the error message reading

Newtonsoft.Json.JsonReaderException: After parsing a value an unexpected character was encountered:

I have the following controller which displays a partial ListView. I am trying to display a list of the People Exposed for each control measure inside a list of control measures.

However when I run it I get the following error:

'System.Collections.Generic.IEnumerable<RACentral.ViewModels.FullControlMeasureListViewModel>' does not contain a definition for 'PersonsExpList' and no extension method 'PersonsExpList' accepting a first argument of type 'System.Collections.Generic.IEnumerable<RACentral.ViewModels.FullControlMeasureListViewModel>' could be found (are you missing a using directive or an assembly reference?)

Line 49:                 </td>
Line 50:                 <td>
Line 51:                     @for (int i = 0; i < Model.PeronsExpList.Count();   i++) 
Line 52:                     { 
Line 53:                     @Html.HiddenFor(x => Model.PeronsExpList[i].PeronExpId) 

Controller:

    public ActionResult FullControlMeasureList(int raId)
    {
        //Populate the list
        var hazards = new List<Hazard>(db.Hazards);
        var controlMeasures = new List<ControlMeasure>(db.ControlMeasures).Where(x => x.RiskAssessmentId == raId);

        var cmcombined = (
                              from g in hazards
                              join f in controlMeasures
                              on new { g.HazardId } equals new { f.HazardId }
                              select new CMCombined
                              {
                                  Activity = f.Activity,
                                  ControlMeasureId = f.ControlMeasureId,
                                  ExistingMeasure = f.ExistingMeasure,
                                  HazardName = g.Name,
                                  LikelihoodId = f.LikelihoodId,
                                  Rating = f.Rating,
                                  RiskAssessmentId = f.RiskAssessmentId,
                                  SeverityId = f.SeverityId,
                                  FurtherMeasure = f.FurtherRating >= 1 ? true : false,
                                  FurtherLikelihoodId = f.FurtherLikelihoodId,
                                  FurtherMeasureText = f.FurtherMeasure,
                                  FurtherRating = f.FurtherRating,
                                  FurtherSeverityId = f.FurtherSeverityId,
                              }).OrderBy(x => x.Activity).ToList();

        var cmPeopleExp = new List<ControlMeasurePeopleExposed>(db.ControlMeasurePeopleExposeds).Where(x => x.RiskAssessmentId == raId);
        var peopleExp = from c in cmPeopleExp
                        join d in db.PeopleExposeds
                        on c.PeopleExposedId equals d.PeopleExposedId
                        orderby d.Name
                        select new RAPeopleExp
                        {
                            RAPeopleExpId = c.PeopleExposedId,
                            PeopleExpId = c.PeopleExposedId,
                            PeopleExpName = d.Name,
                            RiskAssessmentId = c.RiskAssessmentId
                        };

        var model = cmcombined.Select(t => new FullControlMeasureListViewModel
        {
            ControlMeasureId = t.ControlMeasureId,
            HazardName = t.HazardName,
            LikelihoodId = t.LikelihoodId,
            PeopleExposed = t.PeopleExposedName,
            Rating = t.Rating,
            SeverityId = t.SeverityId,
            Activity = t.Activity,
            ExCM = t.ExistingMeasure,
            FurCM = t.FurtherMeasureText,
            FurtherLikelihoodId = t.FurtherLikelihoodId,
            FurtherRating = t.FurtherRating,
            FurtherSeverityId = t.FurtherSeverityId,
            FurtherMeasure = t.FurtherMeasure,
            PersonsExpList =
                            peopleExp.Where(v => v.RiskAssessmentId == t.RiskAssessmentId).Select(
                            x => new PersonsExpListViewModel { PersonExpId = x.PeopleExpId, PeronName = x.PeopleExpName, selected = false }).ToArray()
        });
        return PartialView("_FullControlMeasureList", model);
    }

View Models:

public class FullControlMeasureListViewModel
{
    public int ControlMeasureId { get; set; }

    [Display(Name = "People Exposed")]
    public string PeopleExposed { get; set; }

    [Display(Name = "Hazard")]
    public string HazardName { get; set; }

    [Display(Name = "S")]
    public int SeverityId { get; set; }

    [Display(Name = "L")]
    public int LikelihoodId { get; set; }

    [Display(Name = "R")]
    public int Rating { get; set; }

    [Display(Name = "Activity")]
    public string Activity { get; set; }

    [Display(Name = "Extisting Control Measure")]
    public string ExCM { get; set; }

    [Display(Name = "Further Control Measure")]
    public string FurCM { get; set; }

    [Display(Name = "S")]
    public int? FurtherSeverityId { get; set; }

    [Display(Name = "L")]
    public int? FurtherLikelihoodId { get; set; }

    [Display(Name = "R")]
    public int? FurtherRating { get; set; }

    public bool FurtherMeasure { get; set; }

    public PersonsExpListViewModel[] PersonsExpList { get; set; }
}

    public class PersonsExpListViewModel
{
    public int PersonExpId { get; set; }

    [Display(Name = "Person")]
    public string PeronName { get; set; }

    public bool selected { get; set; }
}

View:

 @model IEnumerable<RACentral.ViewModels.FullControlMeasureListViewModel>
 <table class="table">
 @foreach (var group in Model
            .OrderBy(x => x.HazardName)
            .GroupBy(x => x.HazardName))
 {
    <tr class="group-header">
        <th colspan="12"><h4>@group.Key</h4></th>
    </tr>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Activity)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.PeopleExposed)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.ExCM)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.SeverityId)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.LikelihoodId)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Rating)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.FurCM)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.FurtherSeverityId)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.FurtherLikelihoodId)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.FurtherRating)
        </th>
    </tr>

    foreach (var item in group)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Activity) @Html.HiddenFor(modelItem => item.ControlMeasureId)
            </td>
            <td>
                @for (int i = 0; i < Model.PeronsExpList.Count(); i++) 
                { 
                @Html.HiddenFor(x => Model.PersonsExpList[i].PersonExpId)
                @Html.CheckBoxFor(x => Model.PersonsExpList[i].selected)
                @Html.DisplayFor(x => Model.PersonsExpList[i].PersonName, Model.PeronsExpList[i].PeronName)
                } 
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.ExCM)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.SeverityId)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.LikelihoodId)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Rating)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.FurCM)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.FurtherSeverityId)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.FurtherLikelihoodId)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.FurtherRating)
            </td>
        </tr>
    }
}

I sometimes find myself writing razor for forms like the following:

<h2>Subscription form for @Model.UserName</h2>
@using (Html.BeginForm("Subscribe", "Subscribe", FormMethod.Post)
{
   @Html.Partial("CreditCardForm", Model.PaymentInfo)
   @Html.LabelFor(m => m.PaymentInfo.PromoCode)
   @Html.EditorFor(m => m.PaymentInfo.PromoCode, new{Name="PromoCode"})

   <button type=submit>Submit</button>
}

The CreditCardForm partial is reused in a different view (i.e. to update credit card details) and in that case, the PromoCode is not needed, hence why it's pulled out in this way. This might look like the following:

<h2>Update Credit Card form for @Model.UserName</h2>
@using (Html.BeginForm("UpdateCreditCard", "Subscribe", FormMethod.Post)
{
   @Html.Partial("CreditCardForm", Model.PaymentInfo)

   <button type=submit>Submit</button>
}

The other thing to note here is that the model used in these views have two properties: UserName and PaymentInfo; UserName is a display-only property and PaymentInfo is a model that is to be posted back.

Note the override of the name attribute of the PromoCode property at the bottom so that the PromoCode value is correctly bound to the model that is posted back to the controller action. Leaving it as it is would mean that the PromoCode editor has the default name of PaymentInfo.PromoCode which does not bind correctly to the model.

The action method that the form posts to looks like the following:

    [HttpPost]
    public ActionResult Subscribe(PaymentInfo paymentInfo)
    {
        ...
    }

This has always felt like a hack to me - is there a better/right way to do this?

I have a primary controller/view that uses an @model IEnumberable<ReportModel> for the strongly typed view. I would like to use @TextBoxFor() but this does not work with the IEnumberable (or, at least, intellisense does not like it). Is it necessary to create a partial view or something else to allow use of the strongly typed model in creating form elements?

Hi I am designing a website for chatting and video conferencing with asp web page, signalr using webmatrix but i had this exception.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'IntelliFactory.WebSharper.Core, Version=2.4.0.0, Culture=neutral, PublicKeyToken=451ee5fa653b377d' or one of its dependencies. The system cannot find the file specified.

Source Error:

i display 4 buttons for each elements in a list.

i want to know which button has data inside so i create an ActionResult and this returns true if contains data.

[HttpPost]
public ActionResult TieneNotificacion(string Pnombre, string Pcorreo1, string Pprefijo)
{
var lista = agp.CC15_EscalaMandoPorUsuario(Pnombre,Pcorreo1,Pprefijo);
if(lista != null){
 return Json(true);
}
else{
return Json(false);
}
}

in the view i want to set the button class "btn btn-xs" if the method return false and "btn btn-xs btn-info" if return true.

$(document).ready(function () {
    function tieneNotificacion(Nombre,Correo1,Prefijo){
        $.ajax({

            type: "POST",

            url: "/CentralSoluciones/TieneNotificacion",

            data: { Pnombre: Nombre, 
                Pcorreo1: Correo1,
                Pprefijo: Prefijo },

            success: function (data) {

                if (data) {
                    return "btn btn-xs btn-info"
                }
                else {
                    return "btn btn-xs"
                }

            }

        });
    }
});

and the html tag is like that:

<a href="@Url.Action("Detalles", new { Pnombre= item.Nombre, Pcorreo1=item.Correo1, Pprefijo=list.Prefijo })"
                     class=tieneNotificacion(@item.Nombre,@item.Correo1,@list.Prefijo)>
                    <span>@list.Prefijo</span>
                </a>

I'm developing ASP.NET MVC5 web app. I've seen a lot of stuff about generating pdf from html. However, I didn't find solution of my problem.

I have a html Razor view with elements. User is able to dynamically modify these elements i.e. add a column to a table by clicking on a button.

What I want to do is to generate a pdf document from the CURRENT html view.

I tried to use tools such as Rotativa. Unfortunately it generates pdf based on the static html (which is initally loaded when we refresh the page).

I've also tried the tool called NReco PDF Generator. It has method which generates pdf based on the passed html string. However, I don't know how to pass actual html content to controller and I'm not sure if all css styles would behave properly.

Thanks in advance

var openWos = @Model.MyMaintenanceDashboard.OpenWorkOrders;

Why is Visual Studio saying this is a syntax error? It runs fine, but what would the proper syntax be?

When this button is pressed

<input type="submit" value="Create" class="btn btn-default" />

I would like this html code to be created in the view

<a href='@Url.Action("index", "PatientReadings")'>
        <img src='@Url.Content("~/Images/AWT-Bed.png")'/>
     </a>

I am trying to call an action from the controller using onclick method. For some reason it's not returning action I want, it's always jumping to public ActionResult Index() by default.

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Register" class="btn btn-default" onclick="location.href='@Url.Action("RegisterIndex", "Register")'"/>
        </div>
    </div>

NOTE

I have created view automatically with a model. It's validating input for me by using already generated javascripts. If I change input tag to button it's not gonna do the required validation.

I'm working in a solution in ASP.NET

I have my login .cshtml page with that code:

if (WebSecurity.Login(email, password, rememberMe)) {
            string token = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
        var db = Database.Open("BBDD");
        // Insertar token
        db.Execute("INSERT INTO token (token,date) VALUES ("+token+","+DateTime.Now+"");
         localStorage.setItem("var.token", token);

        Context.RedirectLocal(returnUrl);
        return;
    } else {
        ModelState.AddFormError("Error");
    }

I want to set a token in the localstorage.

How Can I do it?

Thanks in advance.

I have a class:

 public class Customer :IComparable<Customer>
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public int Salary { get; set; }
        }

I also have a List:

Customer cust = new Customer() { Id=10,Name="Jack",Salary= 15000};
            Customer cust1 = new Customer() { Id = 10, Name = "Abby", Salary = 5000 };
            Customer cust2 = new Customer() { Id = 10, Name = "Zed", Salary = 152000 };

            List<Customer> CustomerList = new List<Customer>();
            list.Add(cust);
            list.Add(cust1);
            list.Add(cust2);
            CustomerList.Sort();

I understand why list.Sort wont work on Customer since Customer class has three properties and it does not know how to sort it. But if I implement the interface IComparable in Customer class I am able to sort the Customer List any way i want.

public class Customer :IComparable<Customer>
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public int Salary { get; set; }

            public int CompareTo(Customer other)
            {
                return this.Salary.CompareTo(other.Salary);
            }            
        }

Now my question is.. How does implementing CompareTo method let me sort CustomerList? I am not even overriding Sort Method or anything. I am confused since I have not used CompareTo method at all.

I read http://stackoverflow.com/a/4188041/2064292 but it does not answer my question.

I'm working on a website project and I have this problem in its "Contact Us" page!

I made a form to enable site visitors to be heard and the message will be delivered to different addresses depending on what they chose in the dropdown list regarding the subject of this message. but i can't seem to move forward in this project because an error keeps showing every time I run the page

the error is Compiler Error Message: CS1002: ; expected

and it shows this

Line 28:         }
Line 29:     }
Line 30:     protected void Button1_Click(object sender, EventArgs e)
Line 31:    
Line 32:             SmtpClient client = new SmtpClient();

can someone please help me with this? :'(

I have created a dynamic box plot chart which can produce more than 1 chart every time when the codes is executed. Each box plot chart has different Y axis value range.

Does anyone know how I could get the Y-value range of the chart?

For e.g. I want to get the Y axis value of 1 to 120 from Chart 1 and Y axis value of 1 to 35 from Chart 2 as shown below:

enter image description here

enter image description here Question: How to get Y axis value range displayed on a Box Plot Chart?

Thanks for any help.

I have code, that is not my and I need repair this code. I repair most of code. Can someone help me with this? Because Visual studio says it is only about expression. But I did not find problem.

<script type="text/javascript">
   $(function() { 
    setTimeout(function() { 
    var strip = new PhotoStrip('<%= photoStripR.ClientID  %>',        <%=this.ColumnCount %>,'#<%= photoStripR.ClientID  %>_left','#<%= photoStripR.ClientID  %>_right'
               [
<%-- Seznam obrazku fancybox ma zobrazit v detailu --%>
  <asp:Repeater ID="Repeater1" runat="server" DataSourceID="ItemsSqlDataSource">      <ItemTemplate>'<%# ResolveUrl(Eval("Guid","~/App_Handlers/GetPhotoItemImage.ashx?Guid={0}")) %>',       </ItemTemplate>
     </asp:Repeater>
          ]);
     strip.init();
     },500);
   });
</script>

I want to freeze the column header, so that i set UseStaticHeaders=True.

But i found that the Group Header had alignment problem (please see attached screen capture).

I had tried to use css, but not work.

enter image description here

Thanks

i created a simple web service in asp .net that does some operations:

[WebMethod]
public int Area(int l, int b)
    {
return l * b;
    }

[WebMethod]
public int Perimeter(int l, int b)
{
return 2 * (l +b);
}

and i called it in HTML file, like:

<html>
<head>
<title>WebService Call using HTTP POST</title>
<body>
<form action="http://localhost:56472/WebSite2/Service.asmx/Area" method="POST">
<input name="l">
<input name="b">
<input type="submit" value="Click for Area">
</form>
<form action="http://localhost:56472/WebSite2/Service.asmx/Perimeter" method="POST">
<input name="l">
<input name="b">
<input type="submit" value="Click for Perimeter">
</form>
</body>
</head>
</html>

put this when i click for the result it will be returned as XML:

 <?xml version="1.0" encoding="UTF-8"?>
 <int xmlns="http://tempuri.org/">30</int> 

and what i want is i want the result in HTML not XML, how to do this?

can someone help please?

Thank You :)!