asp.net-mvc-5

postback viewModel is null [duplicate]

ぐ巨炮叔叔 提交于 2019-12-25 17:44:23
问题 This question already has answers here : Asp.Net MVC: Why is my view passing NULL models back to my controller? (2 answers) Closed 3 years ago . i try to search this problem, but could not find a solution for it, please help me : my viewModel: namespace webShop.ViewModels.Home { public class RegisterUserViewModel { public User User { get; set; } public UsersDetaile UsersDetaile { get; set; } public IEnumerable<state> state { get; set; } } } my model: public partial class User { public int Id

How to post an object from MVC controller to Web Api controller?

*爱你&永不变心* 提交于 2019-12-25 16:44:21
问题 Scenario is my MVC view is returning data to Controller action and from my action requirement is to build an object and pass it to an external Web API. I m getting data in my action and building an object as well. Can you please direct me how I should pass object to external Web API. Also should it be JSON, object or xml ? I m giving my controller and Web API code below: Controller action: public ActionResult Submit(FormCollection form) { Options lead = new Options(); lead.Situation = form

How to post an object from MVC controller to Web Api controller?

耗尽温柔 提交于 2019-12-25 16:43:29
问题 Scenario is my MVC view is returning data to Controller action and from my action requirement is to build an object and pass it to an external Web API. I m getting data in my action and building an object as well. Can you please direct me how I should pass object to external Web API. Also should it be JSON, object or xml ? I m giving my controller and Web API code below: Controller action: public ActionResult Submit(FormCollection form) { Options lead = new Options(); lead.Situation = form

Passing multi parameters (radio) from view to controller using array

痞子三分冷 提交于 2019-12-25 14:48:38
问题 I would like to post between 55 and 100 items which could be false or true from view to my controller without using Model. This is my code in Razor View: @using(Html.BeginForm("User","User",FormMethod.Post,new{enctype="multipart/form-data"})) { <input type="radio" name="answer1">Choice one</input> <input type="radio" name="answer1">Choice two</input> <input type="radio" name="answer2">Choice three</input> <input type="radio" name="answer2">Choice four</input> .... <input type="radio" name=

Best way to control Error Message for decimal validation in ViewModel property validation?

梦想与她 提交于 2019-12-25 12:13:14
问题 I have a ViewModel property: public decimal decProperty { get; set; } I have found it difficult to customise the Error message for the above. However if I code the following, I can specify the error message. [RegularExpression(@"\d+(\.\d{1,2})?", ErrorMessage = "Invalid decimal")] public string strProperty { get; set; } Ideally I just want to keep the type as "decimal?". How could I just specify "Invalid decimal" in this case? Thanks. 回答1: You could use the Range attribute as a workaround.

Best way to control Error Message for decimal validation in ViewModel property validation?

自古美人都是妖i 提交于 2019-12-25 12:13:05
问题 I have a ViewModel property: public decimal decProperty { get; set; } I have found it difficult to customise the Error message for the above. However if I code the following, I can specify the error message. [RegularExpression(@"\d+(\.\d{1,2})?", ErrorMessage = "Invalid decimal")] public string strProperty { get; set; } Ideally I just want to keep the type as "decimal?". How could I just specify "Invalid decimal" in this case? Thanks. 回答1: You could use the Range attribute as a workaround.

Trigger modal if submitting valid form in ASP.NET MVC 5 application?

情到浓时终转凉″ 提交于 2019-12-25 11:57:06
问题 I am creating an ASP.NET MVC 5 application. There is a long wait time between the user clicking the "submit" button and the next page to load, so I would like a "please wait" modal to pop up only if the user has submitted a valid form. I have tried the following code, which causes the modal to pop up no matter if the form is valid or not: $('form').submit(function () { $('#waitingModal').show(); }); My application utilizes the jQuery Validate plugin and unobtrusive validation which both came

Passing model to javascript and actions questions

僤鯓⒐⒋嵵緔 提交于 2019-12-25 09:33:25
问题 I’m new to MVC and I’m having a lot of trouble with Partial Views. Hopefully someone can give me some guidance. We’re trying to port our ASP.Net webforms app to MVC. I’ve created a little test app to try to mimic what we’re doing on many of our pages. Based on sample code I found here, I have a View and a Partial view and a Model that contains the Partial model. The view has a drop down list that hides/shows the partial view. When the user selects Hidden, I have a javascript method that hides

SignalR- Jquery : $.connection.chathub returns undefined

此生再无相见时 提交于 2019-12-25 08:48:21
问题 I'm creating a chat application using Asp.net MVC, AngularJs, SignalR and Jquery. In the Chat View when I'm trying set the value for chat object it passes null value the code reference is inside the brackets ( var chat=$.connection.chathub;). No other function works because of this. I'm using "Microsoft.AspNet.SignalR.2.2.2" in this project. And jquery and signalr related scripts such as 'jquery.signalR-2.2.2.js ,jquery-ui-1.12.1.js' and few other jquery libraries as well. Can anyone help me

upload 2 different files to 2 different destinations in table and folders

不想你离开。 提交于 2019-12-25 07:16:43
问题 I have a form that I'm posting 2 different files that belongs to 2 different values in my Db table. Eg. file1=user image , file2=user company logo . So I need to attach the files url to it's db value with my viewModel , something like this:(Will never work) public ActionResult Create(LectureFormViewModel viewModel) { foreach ((string item in Request.Files).viewModel.Image1) { //Do } foreach ((string item in Request.Files).viewModel.Image2) { //Do } var lecture = new Lecture { Image1 = xxx,