當前位置: 首頁>>代碼示例>>C#>>正文


C# Mvc.FormCollection類代碼示例

本文整理匯總了C#中System.Web.Mvc.FormCollection的典型用法代碼示例。如果您正苦於以下問題:C# FormCollection類的具體用法?C# FormCollection怎麽用?C# FormCollection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FormCollection類屬於System.Web.Mvc命名空間,在下文中一共展示了FormCollection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Create

        public ActionResult Create(FormCollection collection)
        {
            var item = new Item();

            try
            {
                // bind
                TryUpdateModel(item);

                // set the rest
                item.Type = _itemTypeRepository.GetById(Convert.ToInt32(collection["Type"]));
                item.CreatedDate = DateTime.Now;
                item.ModifiedDate = DateTime.Now;

                // save
                _itemRepository.Add(item);
                _itemRepository.Save();

                return RedirectToAction("Edit", new {id = item.ID});
            }
            catch
            {
                return View(item);
            }
        }
開發者ID:pattersonc,項目名稱:ShowOff,代碼行數:25,代碼來源:ItemController.cs

示例2: SummaryForApprove

        public ActionResult SummaryForApprove(int id, FormCollection form)
        {
            var campaign = OperationContext.ServiceSession.EM_CampaignsService.Get(c => c.CampaignID == id).FirstOrDefault();
            if (campaign != null)
            {
                campaign.Approved = true;
                campaign.ApprovedBy = OperationContext.CurrentUser.employeeLoginName;
                campaign.ApprovedDate=DateTime.Now;
                OperationContext.ServiceSession.SaveChange();

                //invoke stored procedure, populate data to campaignInstance.
                Entities entity = new Entities();
                var emailInstanceId =
                    OperationContext.ServiceSession.EM_EmailInstancesService.Get(e => e.CampaignID == id)
                        .FirstOrDefault()
                        .EmailInstanceID;
                entity.EM_CampaignInstances_INSERT(emailInstanceId);

                return OperationContext.SendAjaxMessage(AjaxMessageStatus.OperationSuccess, "", "", null);
            }
            else
            {
                return OperationContext.SendAjaxMessage(AjaxMessageStatus.OperationFailed, "campaign is not found", "",
                    null);
            }
        }
開發者ID:simon8029,項目名稱:EmailPromotionManagementDemo,代碼行數:26,代碼來源:SummaryController.cs

示例3: Delete

 public ActionResult Delete(FormCollection collection, long[] ids)
 {
     if (ids.Length == 0)
     {
         FlashWarn("請選擇要刪除的記錄。");
         return Close();
     }
     using (var session = new SessionFactory().OpenSession())
     {
         session.BeginTransaction();
         var models = session.Find<Role>(m => m.Id.In(ids));
         if (models == null || models.Count == 0)
         {
             FlashFailure("你要刪除的角色不存在或者已被刪除!");
             return Close();
         }
         if (models.Any((m => "SYSTEM".Equals(m.CreatedBy))))
         {
             FlashFailure("你要刪除的角色包含係統內置角色,無法刪除!");
             return Close();
         }
         var roleIds = models.Select(n => n.Id).ToArray();
         if (session.Delete(models) &&
             session.Delete<NavigationPriviledge>(m => m.Flag.Equals(NavigationPriviledge.RoleType) && m.OwnerId.In(roleIds)) &&
             session.Delete<AccountNavigationRef>(m => m.Type.Equals(AccountNavigationRef.RoleType) && m.OwnerId.In(roleIds)))
         {
             session.Commit();
             FlashInfo("角色刪除成功");
             return Close();
         }
         session.Rollback();
         FlashError("角色刪除失敗!");
         return View();
     }
 }
開發者ID:dalinhuang,項目名稱:info_platform_i,代碼行數:35,代碼來源:RoleController.cs

示例4: HireGroup

 /// <summary>
 /// Hire Group Selection screen
 /// </summary>
 public ActionResult HireGroup(FormCollection collection)
 {
     if (collection["HireGroupDetailId"] != null)
     {
         var bookingView = new BookingViewModel
         {
             HireGroupDetailId = Convert.ToInt64(collection["HireGroupDetailId"]),
             OperationWorkPlaceId = Convert.ToInt64(collection["OperationWorkPlaceId"]),
             OperationWorkPlaceCode = Convert.ToString(collection["OperationWorkPlaceCode"]),
             StartDt = Convert.ToDateTime(collection["StartDateTime"]),
             EndDt = Convert.ToDateTime(collection["EndDateTime"]),
             TariffTypeCode = Convert.ToString(collection["TariffTypeCode"])
         };
         TempData["Booking"] = bookingView;
         return RedirectToAction("Services");
     }
     //hire group get
     var bookingViewModel = TempData["Booking"] as BookingViewModel;
     var hireGroupRequest = new GetHireGroupRequest();
     if (bookingViewModel != null)
     {
         hireGroupRequest.StartDateTime = bookingViewModel.StartDt;
         hireGroupRequest.EndDateTime = bookingViewModel.EndDt;
         hireGroupRequest.OutLocationId = bookingViewModel.OperationWorkPlaceId;
         hireGroupRequest.ReturnLocationId = bookingViewModel.OperationWorkPlaceId;
         hireGroupRequest.DomainKey = 1;
     }
     IEnumerable<HireGroupDetail> hireGroupDetails = webApiService.GetHireGroupList(hireGroupRequest)  .AvailableHireGroups.Select(x => x.CreateFrom());
     ViewBag.BookingVM = TempData["Booking"] as BookingViewModel;
     return View(hireGroupDetails.ToList());
 }
開發者ID:innoist,項目名稱:GF-FRS,代碼行數:34,代碼來源:BookingController.cs

示例5: Edit

 public ActionResult Edit(int id, FormCollection collection)
 {
     var model = this.ProjectService.GetFile(id);
     this.TryUpdateModel<Files>(model);
     this.ProjectService.SaveFile(model);            
     return this.RefreshParent();
 }
開發者ID:shenxingfu,項目名稱:HaoTang,代碼行數:7,代碼來源:FilesController.cs

示例6: AjaxAddComment

 public ActionResult AjaxAddComment(FormCollection Fm)
 {
     Maticsoft.BLL.SNS.Comments comments = new Maticsoft.BLL.SNS.Comments();
     Maticsoft.Model.SNS.Comments comModel = new Maticsoft.Model.SNS.Comments();
     int num = Globals.SafeInt(Fm["TargetId"], 0);
     int num2 = 3;
     int num3 = 0;
     string source = ViewModelBase.ReplaceFace(Fm["Des"]);
     comModel.CreatedDate = DateTime.Now;
     comModel.CreatedNickName = base.currentUser.NickName;
     comModel.CreatedUserID = base.currentUser.UserID;
     comModel.Description = source;
     comModel.HasReferUser = source.Contains<char>('@');
     comModel.IsRead = false;
     comModel.ReplyCount = 0;
     comModel.TargetId = num;
     comModel.Type = num2;
     comModel.UserIP = base.Request.UserHostAddress;
     num3 = comments.AddEx(comModel);
     if (num3 > 0)
     {
         comModel.CommentID = num3;
         comModel.Description = ViewModelBase.RegexNickName(comModel.Description);
         List<Maticsoft.Model.SNS.Comments> model = new List<Maticsoft.Model.SNS.Comments> {
             comModel
         };
         return this.PartialView("CommentList", model);
     }
     return base.Content("No");
 }
開發者ID:huaminglee,項目名稱:myyyyshop,代碼行數:30,代碼來源:AlbumController.cs

示例7: EndDateTimeDateTimeUtcValueIsSetCorrectlyFromStartDateTimeLocalDateLocalTimeValues

        public void EndDateTimeDateTimeUtcValueIsSetCorrectlyFromStartDateTimeLocalDateLocalTimeValues()
        {
            var timeZoneId = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time").StandardName;
            var startDateTimeLocalDate = "01/16/2012";
            var startDateTimeLocalTime = "1:00";
            var startDateTimeDateTimeLocalValue = startDateTimeLocalDate + " " + startDateTimeLocalTime;

            var endDateTimeLocalDate = "01/16/2012";
            var endDateTimeLocalTime = "3:00";
            var endDateTimeDateTimeLocalValue = endDateTimeLocalDate + " " + endDateTimeLocalTime;

            var form = new FormCollection
                           {
                               {"test.StartDateTime.LocalDate", startDateTimeLocalDate},
                               {"test.StartDateTime.LocalTime", startDateTimeLocalTime},
                               {"test.EndDateTime.LocalTime", endDateTimeLocalTime},
                               {"test.TimeZoneName", timeZoneId}
                           };
            var result = BindModelByFormCollection(form);

            Assert.AreEqual(DateTime.Parse(startDateTimeDateTimeLocalValue), result.StartDateTime.DateTimeLocalValue);
            Assert.AreEqual(DateTime.Parse(startDateTimeDateTimeLocalValue).ToUniversalTime(timeZoneId), result.StartDateTime.DateTimeUtcValue);

            Assert.AreEqual(DateTime.Parse(endDateTimeDateTimeLocalValue), result.EndDateTime.DateTimeLocalValue);
            Assert.AreEqual(DateTime.Parse(endDateTimeDateTimeLocalValue).ToUniversalTime(timeZoneId), result.EndDateTime.DateTimeUtcValue);
        }
開發者ID:rantoine,項目名稱:CSharpMVCDateTimeConversionFramework,代碼行數:26,代碼來源:UiDateTimeRangeModelBinderTest.cs

示例8: Create

        public ActionResult Create(string entityName, FormCollection collection)
        {
            var entity = Admin.GetEntity(entityName);
            if (entity == null)
            {
                return RedirectToAction("NotFound", new { entityName });
            }

            try
            {
                var savedId = _entityService.Create(entity, collection, Request.Files);
                if (savedId != null)
                {
                    _notificator.Success(IlaroAdminResources.AddSuccess, entity.Verbose.Singular);

                    return SaveOrUpdateSucceed(entityName, savedId);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                _notificator.Error(ex.Message);
            }

            var model = new EntityCreateOrEditModel
            {
                Entity = entity,
                PropertiesGroups = _entityService.PrepareGroups(entity)
            };

            return View(model);
        }
開發者ID:anupvarghese,項目名稱:Ilaro.Admin,代碼行數:32,代碼來源:EntityController.cs

示例9: AddUser

        public void AddUser(FormCollection collection, User user)
        {
            UserBLL ub = new UserBLL();
             String message=ub.AddNewUser(collection,user);

             Index();
        }
開發者ID:lightwavebusiness,項目名稱:AMS,代碼行數:7,代碼來源:UserController.cs

示例10: Create

        public ActionResult Create(FormCollection formCollection)
        {
            try {
                Order order = new Order();
                order.ClientID = WebSecurity.CurrentUserId;
                order.Date = DateTime.Now;
                order.ConditionID = db.Conditions.Where(condition => condition.Name.Equals("Оформлен")).FirstOrDefault().ID;
                order.Address = formCollection["address"];
                db.Orders.Add(order);
                db.SaveChanges();
                Cart cart = (Cart)Session["Cart"];
                List<OrderItem> orderItems = new List<OrderItem>();
                foreach (var item in cart.Content) {
                    OrderItem orderItem = new OrderItem();
                    orderItem.BookID = item.Key;
                    orderItem.Count = item.Value;
                    orderItem.OrderID = order.ID;
                    orderItems.Add(orderItem);
                }
                order.OrderItems = orderItems;
                db.Entry(order).State = EntityState.Modified;
                db.SaveChanges();
                ((Cart)Session["Cart"]).Clear();
            } catch {

            }
            return RedirectToAction("Index");
        }
開發者ID:MAKAR1031,項目名稱:BookStore,代碼行數:28,代碼來源:OrdersController.cs

示例11: Edit

        public ActionResult Edit(FormCollection collection)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index");
            }

            try
            {
                Article_section sec = db.CreateObject<Article_section>();

                sec.Article_id = Int32.Parse(collection["Article_id"]);
                sec.User_name = User.Identity.Name;
                sec.Section_heading = collection["Section_heading"];
                sec.Section_text = collection["Section_text"];
                sec.Pub_date = DateTime.Now;
                sec.delete_flag = 0;
                sec.Parent_section = Int32.Parse(collection["Parent_section"]);
                sec.Section_order = Int32.Parse(collection["Section_order"]);

                db.SaveChanges();
                return RedirectToAction("Wiki/Details/" + sec.Article.Title);

            }
            catch
            {
                return View();
            }
        }
開發者ID:martinSternelius,項目名稱:Wikid-C-,代碼行數:29,代碼來源:SectionController.cs

示例12: Create

        public ActionResult Create(FormCollection collection)
        {
            try
            {
                var courseToSubmit = new Course
                {
                    CreatedByUsername = User.Identity.Name,
                    LastUpdateByUsername = User.Identity.Name,
                    CreationDate = DateTime.Now,
                    Description = collection["description"],
                    Name = collection["name"],
                    LastUpdated = DateTime.Now,
                    State = CourseState.Active,
                    NumberOfCourseCompletions = 0
                };

                CoursesModel cm = new CoursesModel();
                var savedCourse = cm.AddOrUpdateCourse(courseToSubmit);

                return RedirectToAction("Create", "CourseContents", new { id = savedCourse.Id });
            }
            catch
            {
                return View();
            }
        }
開發者ID:starvational,項目名稱:BizCollege,代碼行數:26,代碼來源:CoursesController.cs

示例13: Create

        public ActionResult Create(FormCollection form, int? parentId)
        {
            var building = new Building
                             {
                                 Name = Utils.Transliterator.Transliterate(form["Name"])
                             };
            TryUpdateModel(building, new[] { "Title", "SortOrder", "SeoDescription", "SeoKeywords", "ContentType" });
            building.CategoryLevel = 1;
            building.Active = true;
            building.Text = HttpUtility.HtmlDecode(form["Text"]);

            if (parentId.HasValue)
            {
                var parent = _context.Building.First(c => c.Id == parentId);
                parent.Children.Add(building);
            }
            else
            {
                _context.AddToBuilding(building);
            }
            _context.SaveChanges();


            switch (form["ContentType"])
            {
                case "1": return RedirectToAction("Buildings", "Home", new { area = "" });
                case "2": return RedirectToAction("Products", "Home", new { area = "" });
                case "3": return RedirectToAction("Documents", "Home", new { area = "" });
                case "4": return RedirectToAction("WhereToBuy", "Home", new { area = "" });
                case "5": return RedirectToAction("About", "Home", new { area = "" });
            }
            return RedirectToAction("Buildings", "Home", new { area = "" });
        }
開發者ID:fathurxzz,項目名稱:aleqx,代碼行數:33,代碼來源:BuildingController.cs

示例14: Index

 public ActionResult Index(FormCollection collection)
 {
     if (!AttendeeRegistrationIsOpen())
     {
         return View("RegistrationClosed");
     }
     var newAttendee = new Attendee();
     // This will try to update all the fields in the model based on the form collection
     if (TryUpdateModel(newAttendee, "Attendee", collection))
     {
         _repository.AddAttendee(newAttendee);
         _repository.Save();
         SettingsData settings = SettingsData.Default;
         //TODO: localize string replacement
         var message = new MailMessage(settings.EmailFrom,
                                       newAttendee.People.email,
                                       settings.RegistrationSubject,
                                       settings.RegistrationMessage.Replace(
                                         "{name}", newAttendee.People.name).Replace(
                                             "{role}", "Attendee"));
         try
         {
             Mailer.Send(message);
         }
         catch
         {
             //TODO: log this
         }
         return RedirectToAction("Success");
     }
     // TODO: make validation messages show
     // this isn't showing error messages; eventually that should be investigated
     AttendeeEditData data = MakeEditDateFromAttendee(newAttendee);
     return RedirectToAction("Index", data);
 }
開發者ID:quad341,項目名稱:Conferenceware,代碼行數:35,代碼來源:AttendeeRegistrationController.cs

示例15: Create

        public ActionResult Create(CompanyAdvice companyAdvice, FormCollection form)
        {
            if (companyAdvice.CompanysId == null)
            {
                ModelState.AddModelError("CompanysId", "Please choose a company.");
            }
            ValidateAdvice(companyAdvice);

            if (ModelState.IsValid)
            {
                try
                {
                    _adviceApplicationService.AddCompanyAdvice(CurrentMentor, companyAdvice);

                    return RedirectToAction("Index", "Advice");
                }
                catch
                {
                    return RedirectToAction("Create");
                }
            }

            var companies = _companyApplicationService.GetAllCompanies();
            ViewData["Companies"] = new SelectList(companies, "Id", "CompanyName", companyAdvice.CompanysId);
            ViewData["Semaphores"] = _semaphoreApplicationService.GetAllSemaphores();
            SetAdviceTagViewData();
            return View(companyAdvice);
        }
開發者ID:consumentor,項目名稱:Server,代碼行數:28,代碼來源:CompanyAdviceController.cs


注:本文中的System.Web.Mvc.FormCollection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。